# 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 |
---|---|---|---|---|---|---|

467 | 835 | 0 | 467 | 0 | 1 | 0 |

835 | 467 | 1 | 368 | 1 | 0 | 1 |

467 | 368 | 1 | 99 | 0 | 1 | -1 |

368 | 99 | 3 | 71 | 1 | -1 | 4 |

99 | 71 | 1 | 28 | -1 | 4 | -5 |

71 | 28 | 2 | 15 | 4 | -5 | 14 |

28 | 15 | 1 | 13 | -5 | 14 | -19 |

15 | 13 | 1 | 2 | 14 | -19 | 33 |

13 | 2 | 6 | 1 | -19 | 33 | -217 |

2 | 1 | 2 | 0 | 33 | -217 | 467 |

*Source: ExtendedEuclideanAlgorithm.com*

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

123 | 769 | 0 | 123 | 0 | 1 | 0 |

769 | 123 | 6 | 31 | 1 | 0 | 1 |

123 | 31 | 3 | 30 | 0 | 1 | -3 |

31 | 30 | 1 | 1 | 1 | -3 | 4 |

30 | 1 | 30 | 0 | -3 | 4 | -123 |

*Source: ExtendedEuclideanAlgorithm.com*

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

503 | 561 | 0 | 503 | 0 | 1 | 0 |

561 | 503 | 1 | 58 | 1 | 0 | 1 |

503 | 58 | 8 | 39 | 0 | 1 | -8 |

58 | 39 | 1 | 19 | 1 | -8 | 9 |

39 | 19 | 2 | 1 | -8 | 9 | -26 |

19 | 1 | 19 | 0 | 9 | -26 | 503 |

*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 ≡ 374 × 835`

^{-1} (mod 467) ≡ 374 × 250 (mod 467) ≡ 100 (mod 467)`x ≡ 681 × 769`

^{-1} (mod 123) ≡ 681 × 4 (mod 123) ≡ 18 (mod 123)`x ≡ 862 × 561`

^{-1} (mod 503) ≡ 862 × 477 (mod 503) ≡ 223 (mod 503)

**New equations**

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

x ≡ 100 (mod 467)

x ≡ 18 (mod 123)

x ≡ 223 (mod 503)

Now the actual calculation

**Find the common modulus M**

`M = m`

_{1}× m_{2}× ... × m_{k}= 467 × 123 × 503 = 28892823**We calculate the numbers M**_{1}to M_{3}

`M`

,_{1}=M/m_{1}=28892823/467=61869`M`

,_{2}=M/m_{2}=28892823/123=234901`M`

_{3}=M/m_{3}=28892823/503=57441**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 467 61869 0 467 0 1 0 61869 467 132 225 1 0 1 467 225 2 17 0 1 -2 225 17 13 4 1 -2 27 17 4 4 1 -2 27 -110 4 1 4 0 27 -110 467 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 123 234901 0 123 0 1 0 234901 123 1909 94 1 0 1 123 94 1 29 0 1 -1 94 29 3 7 1 -1 4 29 7 4 1 -1 4 -17 7 1 7 0 4 -17 123 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 503 57441 0 503 0 1 0 57441 503 114 99 1 0 1 503 99 5 8 0 1 -5 99 8 12 3 1 -5 61 8 3 2 2 -5 61 -127 3 2 1 1 61 -127 188 2 1 2 0 -127 188 -503 *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**

`= (100 × 61869 × 357 +`

18 × 234901 × 106 +

223 × 57441 × 188)**mod 28892823**

= 8826867 (mod 28892823)

So our answer is 8826867 (mod 28892823).

Verification

So we found that `x ≡ 8826867`

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

835x (mod 467) ≡ 374 (mod 467)

769x (mod 123) ≡ 681 (mod 123)

561x (mod 503) ≡ 862 (mod 503)

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