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

57 | 265 | 0 | 57 | 0 | 1 | 0 |

265 | 57 | 4 | 37 | 1 | 0 | 1 |

57 | 37 | 1 | 20 | 0 | 1 | -1 |

37 | 20 | 1 | 17 | 1 | -1 | 2 |

20 | 17 | 1 | 3 | -1 | 2 | -3 |

17 | 3 | 5 | 2 | 2 | -3 | 17 |

3 | 2 | 1 | 1 | -3 | 17 | -20 |

2 | 1 | 2 | 0 | 17 | -20 | 57 |

*Source: ExtendedEuclideanAlgorithm.com*

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

385 | 969 | 0 | 385 | 0 | 1 | 0 |

969 | 385 | 2 | 199 | 1 | 0 | 1 |

385 | 199 | 1 | 186 | 0 | 1 | -1 |

199 | 186 | 1 | 13 | 1 | -1 | 2 |

186 | 13 | 14 | 4 | -1 | 2 | -29 |

13 | 4 | 3 | 1 | 2 | -29 | 89 |

4 | 1 | 4 | 0 | -29 | 89 | -385 |

*Source: ExtendedEuclideanAlgorithm.com*

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

709 | 828 | 0 | 709 | 0 | 1 | 0 |

828 | 709 | 1 | 119 | 1 | 0 | 1 |

709 | 119 | 5 | 114 | 0 | 1 | -5 |

119 | 114 | 1 | 5 | 1 | -5 | 6 |

114 | 5 | 22 | 4 | -5 | 6 | -137 |

5 | 4 | 1 | 1 | 6 | -137 | 143 |

4 | 1 | 4 | 0 | -137 | 143 | -709 |

*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 ≡ 613 × 265`

^{-1} (mod 57) ≡ 613 × 37 (mod 57) ≡ 52 (mod 57)`x ≡ 980 × 969`

^{-1} (mod 385) ≡ 980 × 89 (mod 385) ≡ 210 (mod 385)`x ≡ 829 × 828`

^{-1} (mod 709) ≡ 829 × 143 (mod 709) ≡ 144 (mod 709)

**New equations**

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

x ≡ 52 (mod 57)

x ≡ 210 (mod 385)

x ≡ 144 (mod 709)

Now the actual calculation

**Find the common modulus M**

`M = m`

_{1}× m_{2}× ... × m_{k}= 57 × 385 × 709 = 15559005**We calculate the numbers M**_{1}to M_{3}

`M`

,_{1}=M/m_{1}=15559005/57=272965`M`

,_{2}=M/m_{2}=15559005/385=40413`M`

_{3}=M/m_{3}=15559005/709=21945**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 57 272965 0 57 0 1 0 272965 57 4788 49 1 0 1 57 49 1 8 0 1 -1 49 8 6 1 1 -1 7 8 1 8 0 -1 7 -57 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 385 40413 0 385 0 1 0 40413 385 104 373 1 0 1 385 373 1 12 0 1 -1 373 12 31 1 1 -1 32 12 1 12 0 -1 32 -385 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 709 21945 0 709 0 1 0 21945 709 30 675 1 0 1 709 675 1 34 0 1 -1 675 34 19 29 1 -1 20 34 29 1 5 -1 20 -21 29 5 5 4 20 -21 125 5 4 1 1 -21 125 -146 4 1 4 0 125 -146 709 *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**

`= (52 × 272965 × 7 +`

210 × 40413 × 32 +

144 × 21945 × 563)**mod 15559005**

= 2916970 (mod 15559005)

So our answer is 2916970 (mod 15559005).

Verification

So we found that `x ≡ 2916970`

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

265x (mod 57) ≡ 613 (mod 57)

969x (mod 385) ≡ 980 (mod 385)

828x (mod 709) ≡ 829 (mod 709)

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