Leandro Junes

Chinese Remainder Theorem

Solves a system of congruences x ≡ aᵢ (mod nᵢ) , combining them two at a time via modular inverses, with every step shown. The moduli need not be pairwise coprime: the system is then solved modulo their least common multiple, or shown to have no solution.

Inputs

Enter at least two congruences. You may add up to eight more.

Congruence 1

Any integer.

Integer ≥ 2.

Congruence 2

Any integer.

Integer ≥ 2.

Try

Result

—

System of 3 congruences

23

x ≡ 23 (mod 105)

x ≡ 2 (mod 3); x ≡ 3 (mod 5); x ≡ 2 (mod 7)
Modulus N
105
product of the moduli
Congruences
3
Folds
2

Pairwise combination steps

—
Fold Folding in g = gcd(n, nᵢ) Inverse used Combined result

Each fold combines the running solution x ≡ a (mod n) with the next congruence x ≡ aᵢ (mod nᵢ), using the inverse of n mod nᵢ (not the other way around) to find the new residue mod n · nᵢ. When g = gcd(n, nᵢ) > 1 the two congruences must agree modulo g (otherwise there is no solution); the inverse is then that of n/g mod nᵢ/g, and the new modulus is lcm(n, nᵢ) = n · nᵢ / g. A dash means nᵢ already divides n, so that congruence adds nothing new.