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
89664089010
66489741101
89412701-2
417561-211
7611-211-13
616011-1389
So our multiplicative inverse is -13 mod 89 ≡ 76
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
5092542101-2
254125401-2509
So our multiplicative inverse is -2 mod 509 ≡ 507
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
140201010
40214020101
So our multiplicative inverse is 0 mod 1 ≡ 0
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 ≡ 905 × 664-1 (mod 89) ≡ 905 × 76 (mod 89) ≡ 72 (mod 89)
x ≡ 677 × 254-1 (mod 509) ≡ 677 × 507 (mod 509) ≡ 173 (mod 509)
x ≡ 795 × 402-1 (mod 1) ≡ 795 × 0 (mod 1) ≡ 0 (mod 1)


Now the actual calculation

  1. Find the common modulus M
    M = m1 × m2 × ... × mk = 89 × 509 × 1 = 45301
  2. We calculate the numbers M1 to M3
    M1=M/m1=45301/89=509,   M2=M/m2=45301/509=89,   M3=M/m3=45301/1=45301
  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
    89509089010
    50989564101
    896412501-1
    64252141-13
    2514111-13-4
    1411133-47
    11332-47-25
    32117-2532
    2120-2532-89
    So our multiplicative inverse is 32 mod 89 ≡ 32
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    5098956401-5
    89641251-56
    6425214-56-17
    25141116-1723
    141113-1723-40
    1133223-40143
    3211-40143-183
    2120143-183509
    So our multiplicative inverse is -183 mod 509 ≡ 326
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    14530101010
    453011453010101
    So our multiplicative inverse is 0 mod 1 ≡ 0
    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
    =  (72 × 509 × 32 +
       173 × 89 × 326 +
       0 × 45301 × 0)   mod 45301
    = 31222 (mod 45301)


    So our answer is 31222 (mod 45301).


Verification

So we found that x ≡ 31222
If this is correct, then the following statements (i.e. the original equations) are true:
664x (mod 89) ≡ 905 (mod 89)
254x (mod 509) ≡ 677 (mod 509)
402x (mod 1) ≡ 795 (mod 1)

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