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

523 | 956 | 0 | 523 | 0 | 1 | 0 |

956 | 523 | 1 | 433 | 1 | 0 | 1 |

523 | 433 | 1 | 90 | 0 | 1 | -1 |

433 | 90 | 4 | 73 | 1 | -1 | 5 |

90 | 73 | 1 | 17 | -1 | 5 | -6 |

73 | 17 | 4 | 5 | 5 | -6 | 29 |

17 | 5 | 3 | 2 | -6 | 29 | -93 |

5 | 2 | 2 | 1 | 29 | -93 | 215 |

2 | 1 | 2 | 0 | -93 | 215 | -523 |

*Source: ExtendedEuclideanAlgorithm.com*

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

477 | 950 | 0 | 477 | 0 | 1 | 0 |

950 | 477 | 1 | 473 | 1 | 0 | 1 |

477 | 473 | 1 | 4 | 0 | 1 | -1 |

473 | 4 | 118 | 1 | 1 | -1 | 119 |

4 | 1 | 4 | 0 | -1 | 119 | -477 |

*Source: ExtendedEuclideanAlgorithm.com*

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

509 | 399 | 1 | 110 | 0 | 1 | -1 |

399 | 110 | 3 | 69 | 1 | -1 | 4 |

110 | 69 | 1 | 41 | -1 | 4 | -5 |

69 | 41 | 1 | 28 | 4 | -5 | 9 |

41 | 28 | 1 | 13 | -5 | 9 | -14 |

28 | 13 | 2 | 2 | 9 | -14 | 37 |

13 | 2 | 6 | 1 | -14 | 37 | -236 |

2 | 1 | 2 | 0 | 37 | -236 | 509 |

*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 ≡ 689 × 956`

^{-1} (mod 523) ≡ 689 × 215 (mod 523) ≡ 126 (mod 523)`x ≡ 930 × 950`

^{-1} (mod 477) ≡ 930 × 119 (mod 477) ≡ 6 (mod 477)`x ≡ 138 × 399`

^{-1} (mod 509) ≡ 138 × 273 (mod 509) ≡ 8 (mod 509)

**New equations**

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

x ≡ 126 (mod 523)

x ≡ 6 (mod 477)

x ≡ 8 (mod 509)

Now the actual calculation

**Find the common modulus M**

`M = m`

_{1}× m_{2}× ... × m_{k}= 523 × 477 × 509 = 126980739**We calculate the numbers M**_{1}to M_{3}

`M`

,_{1}=M/m_{1}=126980739/523=242793`M`

,_{2}=M/m_{2}=126980739/477=266207`M`

_{3}=M/m_{3}=126980739/509=249471**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 523 242793 0 523 0 1 0 242793 523 464 121 1 0 1 523 121 4 39 0 1 -4 121 39 3 4 1 -4 13 39 4 9 3 -4 13 -121 4 3 1 1 13 -121 134 3 1 3 0 -121 134 -523 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 477 266207 0 477 0 1 0 266207 477 558 41 1 0 1 477 41 11 26 0 1 -11 41 26 1 15 1 -11 12 26 15 1 11 -11 12 -23 15 11 1 4 12 -23 35 11 4 2 3 -23 35 -93 4 3 1 1 35 -93 128 3 1 3 0 -93 128 -477 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 509 249471 0 509 0 1 0 249471 509 490 61 1 0 1 509 61 8 21 0 1 -8 61 21 2 19 1 -8 17 21 19 1 2 -8 17 -25 19 2 9 1 17 -25 242 2 1 2 0 -25 242 -509 *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**

`= (126 × 242793 × 134 +`

6 × 266207 × 128 +

8 × 249471 × 242)**mod 126980739**

= 88452501 (mod 126980739)

So our answer is 88452501 (mod 126980739).

Verification

So we found that `x ≡ 88452501`

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

956x (mod 523) ≡ 689 (mod 523)

950x (mod 477) ≡ 930 (mod 477)

399x (mod 509) ≡ 138 (mod 509)

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