Bootstrap
  C.R.T. .com
It doesn't have to be difficult if someone just explains it right.

Welcome to ChineseRemainderTheorem.com!

×

Modal Header

Some text in the Modal Body

Some other text...

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?


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:

nbqr t1t2t3
521387113401-1
38713421191-13
134119115-13-4
119157143-431
151411-431-35
14114031-35521
So our multiplicative inverse is -35 mod 521 ≡ 486
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
2398640239010
8642393147101
23914719201-1
147921551-12
9255137-12-3
55371182-35
371821-35-13
1811805-13239
So our multiplicative inverse is -13 mod 239 ≡ 226
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
17716611101-1
166111511-116
111110-116-177
So our multiplicative inverse is 16 mod 177 ≡ 16
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 ≡ 633 × 387-1 (mod 521) ≡ 633 × 486 (mod 521) ≡ 248 (mod 521)
x ≡ 262 × 864-1 (mod 239) ≡ 262 × 226 (mod 239) ≡ 179 (mod 239)
x ≡ 59 × 166-1 (mod 177) ≡ 59 × 16 (mod 177) ≡ 59 (mod 177)


Now the actual calculation

  1. Find the common modulus M
    M = m1 × m2 × ... × mk = 521 × 239 × 177 = 22039863
  2. We calculate the numbers M1 to M3
    M1=M/m1=22039863/521=42303,   M2=M/m2=22039863/239=92217,   M3=M/m3=22039863/177=124519
  3. We now calculate the modular multiplicative inverses M1-1 to M3-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:

    nbqr t1t2t3
    521423030521010
    4230352181102101
    52110251101-5
    10211931-546
    11332-546-143
    321146-143189
    2120-143189-521
    So our multiplicative inverse is 189 mod 521 ≡ 189
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    239922170239010
    92217239385202101
    23920213701-1
    202375171-16
    371723-16-13
    173526-1371
    3211-1371-84
    212071-84239
    So our multiplicative inverse is -84 mod 239 ≡ 155
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    1771245190177010
    12451917770388101
    177882101-2
    8818801-2177
    So our multiplicative inverse is -2 mod 177 ≡ 175
    Source: ExtendedEuclideanAlgorithm.com
  4. Now we can calculate x with the equation we saw earlier
    x = (a1 × M1 × M1-1   +   a2 × M2 × M2-1   + ... +   ak × Mk × Mk-1)   mod M
    =  (248 × 42303 × 189 +
       179 × 92217 × 155 +
       59 × 124519 × 175)   mod 22039863
    = 8521724 (mod 22039863)


    So our answer is 8521724 (mod 22039863).


Verification

So we found that x ≡ 8521724
If this is correct, then the following statements (i.e. the original equations) are true:
387x (mod 521) ≡ 633 (mod 521)
864x (mod 239) ≡ 262 (mod 239)
166x (mod 177) ≡ 59 (mod 177)

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