# Welcome to ChineseRemainderTheorem.com!

Use the calculator below to get a step-by-step calculation of the Chinese Remainder Theory. Just enter the numbers you would like and press "Calculate" .

This removes all numbers from the textboxes, such that you can fill in your own.

This fills all textboxes with random numbers. If you fill in random numbers yourself, it is very likely that those numbers do not have a solution. To avoid disappointment, use this button instead! It only uses random numbers that do have a solution.

This button is similar to the "Clear everything" button, but only clears the left column.

This is useful if you want your equations to be of the form `x ≡ a (mod m)`

rather than `bx ≡ a (mod m)`

.

In that case, it can be especially useful after using the random numbers button.

Do you want to use more equations? Go ahead and use this button. It adds another row that you can fill in. Not sure what numbers to put in this newly added row? Use the random numbers button again!

Do you have too many rows? Use one of these buttons to remove a row. You can always add a row again using the yellow "Add a row" button.

Are you ready to view a full step-by-step Chinese Remainder Theorem calculation for the numbers you have entered? Then use this button!

**Want to know more?**

- Read about how to execute the Chinese Remainder Theorem
- Discover different ways to calculate multiplicative inverses

Transform the equations

You used one or more of the fields on the left, so your equations are of the form `bx ≡ a mod m`

.

We want them to be of the form `x ≡ a mod m`

, so we need to move the values on the left to the right side of the equation.

For a more detailed explanation about how this works, see this part of our page about how to execute the Chinese Remainder algorithm.

First, we calculate the inverses of the leftmost value on each row:

n | b | q | r | t1 | t2 | t3 |
---|---|---|---|---|---|---|

158 | 353 | 0 | 158 | 0 | 1 | 0 |

353 | 158 | 2 | 37 | 1 | 0 | 1 |

158 | 37 | 4 | 10 | 0 | 1 | -4 |

37 | 10 | 3 | 7 | 1 | -4 | 13 |

10 | 7 | 1 | 3 | -4 | 13 | -17 |

7 | 3 | 2 | 1 | 13 | -17 | 47 |

3 | 1 | 3 | 0 | -17 | 47 | -158 |

*Source: ExtendedEuclideanAlgorithm.com*

n | b | q | r | t1 | t2 | t3 |
---|---|---|---|---|---|---|

511 | 34 | 15 | 1 | 0 | 1 | -15 |

34 | 1 | 34 | 0 | 1 | -15 | 511 |

*Source: ExtendedEuclideanAlgorithm.com*

n | b | q | r | t1 | t2 | t3 |
---|---|---|---|---|---|---|

191 | 277 | 0 | 191 | 0 | 1 | 0 |

277 | 191 | 1 | 86 | 1 | 0 | 1 |

191 | 86 | 2 | 19 | 0 | 1 | -2 |

86 | 19 | 4 | 10 | 1 | -2 | 9 |

19 | 10 | 1 | 9 | -2 | 9 | -11 |

10 | 9 | 1 | 1 | 9 | -11 | 20 |

9 | 1 | 9 | 0 | -11 | 20 | -191 |

*Source: ExtendedEuclideanAlgorithm.com*

Click on any row to reveal a more detailed calculation of each multiplicative inverse.

Now that we now the inverses, let's move the leftmost value on each row to the right of the equation:

`x ≡ 524 × 353`

^{-1} (mod 158) ≡ 524 × 47 (mod 158) ≡ 138 (mod 158)`x ≡ 352 × 34`

^{-1} (mod 511) ≡ 352 × 496 (mod 511) ≡ 341 (mod 511)`x ≡ 739 × 277`

^{-1} (mod 191) ≡ 739 × 20 (mod 191) ≡ 73 (mod 191)

**New equations**

So now we have the following equations of the form x ≡ a (mod m):

x ≡ 138 (mod 158)

x ≡ 341 (mod 511)

x ≡ 73 (mod 191)

Now the actual calculation

**Find the common modulus M**

`M = m`

_{1}× m_{2}× ... × m_{k}= 158 × 511 × 191 = 15420958**We calculate the numbers M**_{1}to M_{3}

`M`

,_{1}=M/m_{1}=15420958/158=97601`M`

,_{2}=M/m_{2}=15420958/511=30178`M`

_{3}=M/m_{3}=15420958/191=80738**We now calculate the modular multiplicative inverses M**_{1}^{-1}to M_{3}^{-1}

Have a look at the page that explains how to calculate modular multiplicative inverse.

Using, for example, the Extended Euclidean Algorithm, we will find that:

n b q r t1 t2 t3 158 97601 0 158 0 1 0 97601 158 617 115 1 0 1 158 115 1 43 0 1 -1 115 43 2 29 1 -1 3 43 29 1 14 -1 3 -4 29 14 2 1 3 -4 11 14 1 14 0 -4 11 -158 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 511 30178 0 511 0 1 0 30178 511 59 29 1 0 1 511 29 17 18 0 1 -17 29 18 1 11 1 -17 18 18 11 1 7 -17 18 -35 11 7 1 4 18 -35 53 7 4 1 3 -35 53 -88 4 3 1 1 53 -88 141 3 1 3 0 -88 141 -511 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 191 80738 0 191 0 1 0 80738 191 422 136 1 0 1 191 136 1 55 0 1 -1 136 55 2 26 1 -1 3 55 26 2 3 -1 3 -7 26 3 8 2 3 -7 59 3 2 1 1 -7 59 -66 2 1 2 0 59 -66 191 *Source: ExtendedEuclideanAlgorithm.com*

**Now we can calculate x with the equation we saw earlier**

`x = (a`

_{1}× M_{1}× M_{1}^{-1}+ a_{2}× M_{2}× M_{2}^{-1}+ ... + a_{k}× M_{k}× M_{k}^{-1})**mod M**

`= (138 × 97601 × 11 +`

341 × 30178 × 141 +

73 × 80738 × 125)**mod 15420958**

= 7316328 (mod 15420958)

So our answer is 7316328 (mod 15420958).

Verification

So we found that `x ≡ 7316328`

If this is correct, then the following statements (i.e. the original equations) are true:

353x (mod 158) ≡ 524 (mod 158)

34x (mod 511) ≡ 352 (mod 511)

277x (mod 191) ≡ 739 (mod 191)

Let's see whether that's indeed the case if we use x ≡ 7316328.