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

821 | 190 | 4 | 61 | 0 | 1 | -4 |

190 | 61 | 3 | 7 | 1 | -4 | 13 |

61 | 7 | 8 | 5 | -4 | 13 | -108 |

7 | 5 | 1 | 2 | 13 | -108 | 121 |

5 | 2 | 2 | 1 | -108 | 121 | -350 |

2 | 1 | 2 | 0 | 121 | -350 | 821 |

*Source: ExtendedEuclideanAlgorithm.com*

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

257 | 870 | 0 | 257 | 0 | 1 | 0 |

870 | 257 | 3 | 99 | 1 | 0 | 1 |

257 | 99 | 2 | 59 | 0 | 1 | -2 |

99 | 59 | 1 | 40 | 1 | -2 | 3 |

59 | 40 | 1 | 19 | -2 | 3 | -5 |

40 | 19 | 2 | 2 | 3 | -5 | 13 |

19 | 2 | 9 | 1 | -5 | 13 | -122 |

2 | 1 | 2 | 0 | 13 | -122 | 257 |

*Source: ExtendedEuclideanAlgorithm.com*

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

71 | 669 | 0 | 71 | 0 | 1 | 0 |

669 | 71 | 9 | 30 | 1 | 0 | 1 |

71 | 30 | 2 | 11 | 0 | 1 | -2 |

30 | 11 | 2 | 8 | 1 | -2 | 5 |

11 | 8 | 1 | 3 | -2 | 5 | -7 |

8 | 3 | 2 | 2 | 5 | -7 | 19 |

3 | 2 | 1 | 1 | -7 | 19 | -26 |

2 | 1 | 2 | 0 | 19 | -26 | 71 |

*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 ≡ 58 × 190`

^{-1} (mod 821) ≡ 58 × 471 (mod 821) ≡ 225 (mod 821)`x ≡ 730 × 870`

^{-1} (mod 257) ≡ 730 × 135 (mod 257) ≡ 119 (mod 257)`x ≡ 902 × 669`

^{-1} (mod 71) ≡ 902 × 45 (mod 71) ≡ 49 (mod 71)

**New equations**

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

x ≡ 225 (mod 821)

x ≡ 119 (mod 257)

x ≡ 49 (mod 71)

Now the actual calculation

**Find the common modulus M**

`M = m`

_{1}× m_{2}× ... × m_{k}= 821 × 257 × 71 = 14980787**We calculate the numbers M**_{1}to M_{3}

`M`

,_{1}=M/m_{1}=14980787/821=18247`M`

,_{2}=M/m_{2}=14980787/257=58291`M`

_{3}=M/m_{3}=14980787/71=210997**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 821 18247 0 821 0 1 0 18247 821 22 185 1 0 1 821 185 4 81 0 1 -4 185 81 2 23 1 -4 9 81 23 3 12 -4 9 -31 23 12 1 11 9 -31 40 12 11 1 1 -31 40 -71 11 1 11 0 40 -71 821 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 257 58291 0 257 0 1 0 58291 257 226 209 1 0 1 257 209 1 48 0 1 -1 209 48 4 17 1 -1 5 48 17 2 14 -1 5 -11 17 14 1 3 5 -11 16 14 3 4 2 -11 16 -75 3 2 1 1 16 -75 91 2 1 2 0 -75 91 -257 *Source: ExtendedEuclideanAlgorithm.com*

n b q r t1 t2 t3 71 210997 0 71 0 1 0 210997 71 2971 56 1 0 1 71 56 1 15 0 1 -1 56 15 3 11 1 -1 4 15 11 1 4 -1 4 -5 11 4 2 3 4 -5 14 4 3 1 1 -5 14 -19 3 1 3 0 14 -19 71 *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**

`= (225 × 18247 × 750 +`

119 × 58291 × 91 +

49 × 210997 × 52)**mod 14980787**

= 8472124 (mod 14980787)

So our answer is 8472124 (mod 14980787).

Verification

So we found that `x ≡ 8472124`

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

190x (mod 821) ≡ 58 (mod 821)

870x (mod 257) ≡ 730 (mod 257)

669x (mod 71) ≡ 902 (mod 71)

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