An old puzzle from the Chinese mathematician Sunzi asks for a number with given remainders on division by 3, by 5 and by 7. Systems like this are everywhere in modern number theory and computing: a number can be stored by its remainders mod a few coprime moduli, and the Chinese Remainder Theorem (CRT) says nothing is lost. It is built from modular inverses.
Theorem. If $\gcd(m, n) = 1$, then for any $a$ and $b$ the system $$x \equiv a \pmod{m}, \qquad x \equiv b \pmod{n}$$ has a solution, and any two solutions are congruent mod $mn$. So there is exactly one solution mod $mn$.
Why it works
Worked example: Two congruences
- $x = 2 + 5k$. Then $2 + 5k \equiv 3 \pmod{7}$, so $5k \equiv 1 \pmod{7}$.
- $5^{-1} \equiv 3 \pmod{7}$ (since $15 \equiv 1$), so $k \equiv 3$, and $x = 2 + 15 = 17$.
- Check: $17 = 3 \cdot 5 + 2$ and $17 = 2 \cdot 7 + 3$. All solutions: $x \equiv 17 \pmod{35}$.
Answer: $x \equiv 17 \pmod{35}$.
Worked example: Three congruences
- Combine the first two: $x = 1 + 3k$, $3k \equiv 1 \pmod{4}$, $k \equiv 3$, so $x \equiv 10 \pmod{12}$.
- Combine with the third: $x = 10 + 12j$, $12j \equiv -7 \pmod{5}$, that is $2j \equiv 3$, so $j \equiv 4$ and $x = 58$.
- Check: $58 = 3 \cdot 19 + 1 = 4 \cdot 14 + 2 = 5 \cdot 11 + 3$.
Answer: $x = 58$ (unique mod $60$).
Worked example: Moduli with a common factor
- $\gcd(4, 6) = 2$, so both congruences say something mod 2: $x$ is odd and $x$ is odd. They agree, so there are solutions.
- Try odd numbers $\equiv 1 \pmod{4}$: $1, 5, 9$. $9 \equiv 3 \pmod{6}$, so $x \equiv 9 \pmod{12}$, the lcm.
- Below 24: $x = 9$ and $x = 21$, two solutions mod 24 rather than one.
Answer: $x = 9$ or $21$.
Common mistake
Key idea