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
1313070131010
307131245101
1314524101-2
4541141-23
414101-23-32
41403-32131
So our multiplicative inverse is -32 mod 131 ≡ 99
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
1399470139010
9471396113101
13911312601-1
11326491-15
26928-15-11
98115-1116
8180-1116-139
So our multiplicative inverse is 16 mod 139 ≡ 16
Source: ExtendedEuclideanAlgorithm.com

nbqr t1t2t3
3168170316010
8173162185101
316185113101-1
1851311541-12
13154223-12-5
5423282-512
23827-512-29
871112-2941
7170-2941-316
So our multiplicative inverse is 41 mod 316 ≡ 41
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 ≡ 754 × 307-1 (mod 131) ≡ 754 × 99 (mod 131) ≡ 107 (mod 131)
x ≡ 237 × 947-1 (mod 139) ≡ 237 × 16 (mod 139) ≡ 39 (mod 139)
x ≡ 551 × 817-1 (mod 316) ≡ 551 × 41 (mod 316) ≡ 155 (mod 316)


Now the actual calculation

  1. Find the common modulus M
    M = m1 × m2 × ... × mk = 131 × 139 × 316 = 5754044
  2. We calculate the numbers M1 to M3
    M1=M/m1=5754044/131=43924,   M2=M/m2=5754044/139=41396,   M3=M/m3=5754044/316=18209
  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
    131439240131010
    4392413133539101
    1313931401-3
    39142111-37
    141113-37-10
    113327-1037
    3211-1037-47
    212037-47131
    So our multiplicative inverse is -47 mod 131 ≡ 84
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    139413960139010
    41396139297113101
    13911312601-1
    11326491-15
    26928-15-11
    98115-1116
    8180-1116-139
    So our multiplicative inverse is 16 mod 139 ≡ 16
    Source: ExtendedEuclideanAlgorithm.com

    nbqr t1t2t3
    316182090316010
    1820931657197101
    316197111901-1
    1971191781-12
    11978141-12-3
    78411372-35
    413714-35-8
    374915-877
    4140-877-316
    So our multiplicative inverse is 77 mod 316 ≡ 77
    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
    =  (107 × 43924 × 84 +
       39 × 41396 × 16 +
       155 × 18209 × 77)   mod 5754044
    = 4999591 (mod 5754044)


    So our answer is 4999591 (mod 5754044).


Verification

So we found that x ≡ 4999591
If this is correct, then the following statements (i.e. the original equations) are true:
307x (mod 131) ≡ 754 (mod 131)
947x (mod 139) ≡ 237 (mod 139)
817x (mod 316) ≡ 551 (mod 316)

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