CalcSeed

Chinese Remainder Theorem Calculator

Enter three congruences x ≡ r (mod m) to find the solution modulo the product of the moduli.

=
Quick answer: with the default inputs (2, 3, 3, 5), the solution x is 23. At these inputs: modulus = 105. Change any input to update the result.
Solution x
—

What this calculator solves

The Chinese remainder theorem solves systems like x ≡ 2 (mod 3), x ≡ 3 (mod 5) and x ≡ 2 (mod 7): find every x that leaves remainder 2 when divided by 3, remainder 3 when divided by 5, and remainder 2 when divided by 7. For pairwise coprime moduli there is exactly one solution modulo the product, and here it is x = 23 modulo 105. The calculator takes your three remainders and moduli and returns that unique answer.

What the theorem guarantees

x≡ri(modmi)x \equiv r_i \pmod{m_i}

The guarantee is existence and uniqueness: when the moduli are pairwise coprime, some x satisfies all three congruences, and every other solution differs from it by a multiple of m1 × m2 × m3. There is no smaller modulus to check against — the product is the natural period of the system. The construction below shows why the product appears: each congruence contributes a term that lives on a cycle of exactly that length.

How the construction works

The classical method builds one term per congruence. For each i, let Mi = M ÷ mi, where M = m1 × m2 × m3. Then Mi is divisible by the other two moduli, so it vanishes modulo them, and multiplying it by a suitable inverse makes it equal 1 modulo its own mi. Scaling that unit by ri produces a number matching the i-th congruence and contributing nothing to the other two, so the sum of the three terms matches all three at once.

Modular inverses

The inverse of a modulo m is the number that multiplies a up to 1 modulo m. For example, the inverse of 2 modulo 3 is 2, because 2 × 2 = 4 ≡ 1 (mod 3). Inverses exist exactly when gcd(a, m) = 1, which is another face of the coprimality condition. The extended Euclidean algorithm finds them quickly, and that is what the calculator runs internally.

Worked example at the defaults

Solve x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7). Step 1: M = 3 × 5 × 7 = 105. Step 2: M1 = 105 ÷ 3 = 35, M2 = 105 ÷ 5 = 21, M3 = 105 ÷ 7 = 15. Step 3: inverses — 35 mod 3 = 2 and the inverse of 2 mod 3 is 2; 21 mod 5 = 1, inverse 1; 15 mod 7 = 1, inverse 1. Step 4: terms are 2 × 35 × 2 = 140, 3 × 21 × 1 = 63, and 2 × 15 × 1 = 30. Step 5: sum 140 + 63 + 30 = 233, then 233 − 2 × 105 = 23. The calculator returns x = 23 (mod 105).

CongruenceMi = M/miMi mod miInverseTerm ri × Mi × inverse
x ≡ 2 (mod 3)3522140
x ≡ 3 (mod 5)211163
x ≡ 2 (mod 7)151130

Why each term works

The terms sum to 233, and reducing modulo 105 once gives 23. Each term individually satisfies its own congruence while remaining 0 modulo the other two moduli, which is why the total satisfies all three simultaneously.

Checking the answer

Verification takes three divisions: 23 ÷ 3 = 7 remainder 2; 23 ÷ 5 = 4 remainder 3; 23 ÷ 7 = 3 remainder 2. All three match the required remainders, so 23 is correct. The next solutions are 23 + 105 = 128 and 23 + 210 = 333 — every solution is 23 plus a multiple of 105, and 23 is the smallest non-negative representative.

When no solution exists

Coprimality is not decoration. With moduli 4 and 6, which share the factor 2, the pair of conditions x ≡ 1 (mod 4) and x ≡ 2 (mod 6) has no solution at all: the first forces x to be odd, the second forces x to be even. A different pair of remainders with the same moduli can have several solutions modulo 24 instead of one. This is why the calculator expects pairwise coprime moduli like 3, 5 and 7 — only then is the answer unique and the inverse-based construction valid.

Where the theorem is used

  • Cryptography: RSA decryption uses CRT to work modulo p and q separately, roughly four times faster than the direct route.
  • Calendar and cycle puzzles: finding a day that is simultaneously the 3rd day of a 7-day cycle and the 20th of a 30-day cycle.
  • Computer science: reconstructing large integers from remainders in parallel arithmetic and error-correcting codes.
  • Competition math: remainder puzzles are a fixed fixture of number-theory rounds.

The classic puzzle form asks for a number leaving specified remainders — the oldest recorded version, from the 3rd-century Chinese text of Sunzi, counts troops by threes, fives and sevens and gives exactly the system the defaults solve. Modern implementations run the same construction on moduli with hundreds of digits, where the extended Euclidean algorithm does the inverse-finding work that the worked example above does by inspection.

Frequently asked questions

What is the answer for the default system?

x = 23 modulo 105. It leaves remainder 2 when divided by 3, remainder 3 when divided by 5 and remainder 2 when divided by 7, and it is the smallest non-negative solution.

What if the moduli are not coprime?

A solution may not exist, as with x ≡ 1 (mod 4) and x ≡ 2 (mod 6), where one condition demands an odd x and the other an even one. When a solution does exist it may not be unique, so the standard theorem needs pairwise coprime moduli.

How do I check the answer?

Divide by each modulus and compare remainders: 23 ÷ 3 leaves 2, 23 ÷ 5 leaves 3 and 23 ÷ 7 leaves 2. All three must match the entered r values.

Why is the modulus of the answer the product?

105 = 3 × 5 × 7 is the natural period: adding 105 to a solution changes none of the three remainders. The full solution set is x = 23 + 105t for any integer t.

What is a modular inverse?

The number that multiplies a given value to 1 modulo m, such as 2 × 2 = 4 ≡ 1 (mod 3). Inverses exist only when the two numbers are coprime, which is why the construction needs coprime moduli.

Can the remainders be larger than the moduli?

Reduce them first: x ≡ 5 (mod 3) is the same condition as x ≡ 2 (mod 3), since 5 − 2 = 3. The construction works with either form, but smaller numbers keep the arithmetic tidy.

How do I solve more than three congruences?

Apply the theorem twice: solve two congruences, then combine that solution with the third as a new two-congruence system whose moduli are 105 and m4. Each round multiplies the modulus, so four coprime moduli give a solution modulo their product.

Does the theorem work for huge moduli?

Yes — the running time grows only with the number of digits, which is how RSA implementations split a 2048-bit decryption into two 1024-bit halves and finish about four times faster.

Method and sources

Calculation basis

Results follow exact mathematical definitions; the arithmetic is deterministic and can be verified by hand from the steps shown.

Last updated: November 18, 2026
Formula & data sources
  • Chinese remainder theorem for three simultaneous congruences.

Cite this page

Reference formats
APA 7CalcSeed. (2026, November 18). Chinese Remainder Theorem Calculator. https://calcseed.com/c/math/chinese-remainder-calculator/
MLA 9"Chinese Remainder Theorem Calculator." CalcSeed, 18 Nov. 2026, calcseed.com/c/math/chinese-remainder-calculator/.
ChicagoCalcSeed. "Chinese Remainder Theorem Calculator." Last modified November 18, 2026. https://calcseed.com/c/math/chinese-remainder-calculator/

Related calculators