Chinese Remainder Theorem — Merging Two Congruences

Solve x ≡ a₁ (mod m₁) and x ≡ a₂ (mod m₂). Watch the two residue classes intersect into one class modulo the lcm, and the unique solution appear in [0, M).

x ≡ (mod ) x ≡ (mod ) step 0

Residue classes on the number line [0, M)

x ≡ a₁ (mod m₁) x ≡ a₂ (mod m₂) satisfies both = solution

Merge computation

Press Step to begin.
solution: —
We merge the two congruences using x = a₁ + m₁·t, solving for t modulo m₂. If the moduli share a factor g, a solution exists only when a₁ ≡ a₂ (mod g).

Presets

How to read it: the number line shows every x in [0, lcm). Blue cells satisfy the first congruence, gold cells the second, and green cells satisfy both — those green cells are the solutions. A coprime pair always has exactly one green cell per lcm; a non-coprime consistent pair also has exactly one; an inconsistent pair has none (no green cells), which the merge computation reports as NONE.
Self-contained visualization. The combined modulus is lcm(m1, m2) (= the product when coprime). Editable a₁, m₁, a₂, m₂ above; try non-coprime moduli such as (2 mod 6) & (8 mod 12), or an inconsistent pair like (1 mod 4) & (2 mod 6). See junior.md and professional.md for the merge derivation and the gcd consistency proof.