Chinese Remainder Calculator

Solve systems of 2 or 3 congruences with the Chinese Remainder Theorem. Normalize residues, merge non-coprime systems, verify every modulus, and list the full solution family.

Congruence 1

Congruence 2

Congruence 3

Smallest solution
23
Least non-negative x that satisfies every congruence
Combined modulus
105
All solutions are x + kM
Next solution
128
Add 105 once
Pairwise coprime?
Yes
Direct CRT form applies
Product of moduli
105
Matches combined modulus
Verified congruences
3/3
Every normalized residue matches the final solution
Solution family
x = 23 + k * 105
k can be any integer
Input count
3
Number of congruences included in the merge

Normalized congruences

#OriginalNormalizedCheck at x = 23
1x congruent to 2 (mod 3)x congruent to 2 (mod 3)23 mod 3 = 2
2x congruent to 3 (mod 5)x congruent to 3 (mod 5)23 mod 5 = 3
3x congruent to 2 (mod 7)x congruent to 2 (mod 7)23 mod 7 = 2

Merge steps

StepCurrent systemNext congruencegcdDifferenceMultiplierMerged result
1x congruent to 2 (mod 3)x congruent to 3 (mod 5)112x congruent to 8 (mod 15)
2x congruent to 8 (mod 15)x congruent to 2 (mod 7)1-61x congruent to 23 (mod 105)

Residue map

Congruence 1: residue 2 mod 3x = 23
03
Congruence 2: residue 3 mod 5x = 23
05
Congruence 3: residue 2 mod 7x = 23
07

First 5 solutions in the residue class

kx = x0 + kMmod n1mod n2mod n3
023232
1128232
2233232
3338232
4443232
Planning notes, formulas, and examples

About the Chinese Remainder Calculator

The Chinese Remainder Theorem is the standard tool for solving simultaneous congruences such as x congruent to 2 mod 3, x congruent to 3 mod 5, and x congruent to 2 mod 7. Instead of testing values one by one, CRT combines the separate modular conditions into a single residue class x congruent to r mod M. That final statement describes every solution at once, which is exactly what makes CRT so valuable in number theory, cryptography, scheduling cycles, coding theory, and contest math.

This calculator handles both the textbook CRT case with pairwise-coprime moduli and the more useful real-world case where moduli can share factors. It first normalizes every remainder into the standard range 0 through n-1, then merges the congruences one by one using the extended Euclidean algorithm. If the system is compatible, you get the smallest non-negative solution, the combined modulus, and a list of subsequent solutions. If the system is inconsistent, the calculator shows exactly where the merge fails and why the residue difference breaks compatibility.

The extra detail matters. Students can inspect each merge step instead of memorizing a black-box rule, while engineers and programmers can confirm that a modular system is valid before plugging it into downstream logic. The residue map, verification table, and solution-family list make the result immediately usable for both learning and applied work.

When This Page Helps

Solving a congruence system by hand usually means juggling products of moduli, modular inverses, gcd checks, and normalization rules all at once. That is manageable for one homework example, but it becomes fragile as soon as one modulus is negative, one remainder lies outside the standard range, or two moduli are not coprime. This calculator does the bookkeeping while still exposing the arithmetic: normalized congruences, gcd compatibility checks, merge multipliers, and the final residue class. It is especially useful for validating programming answers, checking cryptography exercises, and demonstrating how generalized CRT works when the moduli share factors.

How to Use the Inputs

  1. Choose whether your system has 2 or 3 congruences.
  2. Enter each remainder ai and modulus ni. Moduli must be integers greater than 1.
  3. Use a preset if you want to test a classic CRT example, a non-coprime solvable system, or an incompatible system.
  4. Set how many solution rows you want to list after the smallest solution is found.
  5. Read the output cards for the smallest solution, combined modulus, and solution family.
  6. Check the normalized congruence table to see every remainder converted into standard modular form.
  7. Review the merge-steps table to understand the gcd checks, multiplier, and merged modulus at each stage.
  8. Use the residue map and solution-family table to verify that every listed solution satisfies every original congruence.
Formula used
For a pair of congruences x congruent to a (mod m) and x congruent to b (mod n), let g = gcd(m, n). A solution exists only if a - b is divisible by g. When it is, write m = g*m1 and n = g*n1, solve m1*t congruent to (b - a)/g (mod n1), then combine to x congruent to a + m*t (mod lcm(m, n)). In the pairwise-coprime case, this reduces to the classic CRT construction with modular inverses.

Example Calculation

Result: x congruent to 23 (mod 105)

The smallest non-negative solution is 23 because 23 mod 3 = 2, 23 mod 5 = 3, and 23 mod 7 = 2. Since 3, 5, and 7 are pairwise coprime, the combined modulus is their product 105, so every solution has the form x = 23 + 105k.

Tips & Best Practices

  • Always normalize remainders first. A statement like x congruent to -1 mod 7 is easier to work with as x congruent to 6 mod 7.
  • If two moduli share a gcd greater than 1, do not assume the system fails. It only fails when the residue difference is not divisible by that gcd.
  • In the pairwise-coprime case, the final modulus is simply the product of all moduli.
  • If you only need one representative solution, use the smallest non-negative one. If you need every solution, keep the full residue-class form x = r + kM.
  • CRT is often easier to verify than to derive. Plug the final x back into each modulus check before moving on.
  • For programming contests and cryptography tasks, keep track of overflow when multiplying large moduli. The math may be simple even when the integers are not.

Why Generalized CRT Matters

Textbook treatments often present CRT only for pairwise-coprime moduli because the formulas are clean. Real problems are messier. Shared factors show up in clock arithmetic, packet scheduling, and programmatic constraint systems. In that broader setting, the important question is not just whether the moduli are coprime, but whether the congruences are compatible. That is why this calculator exposes the gcd and residue-difference check at each merge step.

Reading The Solution Family

Once the system is merged, the result x congruent to r mod M is stronger than a single numeric answer. It tells you the smallest solution r, the spacing M between every subsequent solution, and the exact structure of the entire set. That is useful when you need the first solution above a threshold, the next event in a repeating system, or a quick way to generate test cases.

CRT And Modular Inverses

The engine underneath CRT is the modular inverse, usually found with the extended Euclidean algorithm. When two reduced moduli are coprime, the inverse lets you solve for the multiplier that aligns one residue class with another. Understanding that link is valuable because the same inverse computation powers modular division, linear congruence solving, and many cryptographic routines.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • It solves systems of simultaneous modular equations. Instead of finding one x for one modulus, CRT finds the residue class of all x values that satisfy several congruence conditions at once.