Key idea of this section
If n = n₁n₂⋯nₖ with the nᵢ pairwise coprime, then ℤ/nℤ ≅ ℤ/n₁ℤ × ℤ/n₂ℤ × ⋯ × ℤ/nₖℤ as rings.
Statement and proof
The problem goes back to the Sunzi Suanjing (third to fifth century): find a number that leaves remainder 2 on division by 3, remainder 3 on division by 5, and remainder 2 on division by 7. The answer 23 (unique modulo 105) illustrates the general theorem.
Theorem 5.1 (Chinese remainder theorem). Let n₁, …, nₖ be pairwise coprime positive integers and n = n₁⋯nₖ. The map
ψ : ℤ/nℤ → ℤ/n₁ℤ × ⋯ × ℤ/nₖℤ, x mod n ↦ (x mod n₁, …, x mod nₖ)
is a ring isomorphism. In particular the system x ≡ aᵢ (mod nᵢ), i = 1, …, k, has a solution, unique modulo n.
Proof. ψ is well defined (each nᵢ divides n) and a ring homomorphism. If ψ(x) = 0 then every nᵢ divides x; since the nᵢ are pairwise coprime their product divides x (induction with Corollary 1.4), so x ≡ 0 (mod n). Thus ψ is injective, and since both sides have n elements it is bijective. ∎
The proof is non-constructive, but an explicit inverse is easy. Let Nᵢ = n/nᵢ; since gcd(Nᵢ, nᵢ) = 1 there is Mᵢ with NᵢMᵢ ≡ 1 (mod nᵢ). The numbers eᵢ = NᵢMᵢ satisfy eᵢ ≡ 1 (mod nᵢ) and eᵢ ≡ 0 (mod nⱼ) for j ≠ i (they are the idempotents of the product ring), so x = ∑ aᵢeᵢ solves the system.
Worked example (Sunzi). n = 105. N₁ = 35 ≡ 2 (mod 3), M₁ = 2, e₁ = 70. N₂ = 21 ≡ 1 (mod 5), e₂ = 21. N₃ = 15 ≡ 1 (mod 7), e₃ = 15. Then
x ≡ 2 · 70 + 3 · 21 + 2 · 15 = 233 ≡ 23 (mod 105).
In practice one often solves the congruences one at a time. Worked example: x ≡ 3 (mod 8), x ≡ 5 (mod 9), x ≡ 2 (mod 5). From the first, x = 3 + 8t; then 3 + 8t ≡ 5 (mod 9) gives −t ≡ 2, t ≡ 7, so x ≡ 59 (mod 72). Then 59 + 72s ≡ 2 (mod 5) gives 4 + 2s ≡ 2, 2s ≡ 3, s ≡ 4, so x ≡ 59 + 288 = 347 (mod 360).
Non-coprime moduli
Proposition 5.2. The system x ≡ a (mod m), x ≡ b (mod n) is solvable if and only if a ≡ b (mod gcd(m, n)), and then the solution is unique modulo lcm(m, n).
Proof. x = a + mt solves the second congruence iff mt ≡ b − a (mod n), which by Theorem 3.2 is solvable iff gcd(m, n) | b − a, with t unique modulo n/gcd(m, n), i.e. x unique modulo m · n/gcd(m, n) = lcm(m, n). ∎
For example x ≡ 5 (mod 12) and x ≡ 11 (mod 18) is solvable because 5 ≡ 11 (mod 6), and the solution is x ≡ 29 (mod 36).
Consequences
Restricting ψ to units gives a group isomorphism (ℤ/nℤ)× ≅ ∏ (ℤ/nᵢℤ)×, so φ(mn) = φ(m)φ(n) for coprime m, n. Since φ(pᵉ) = pᵉ − pᵉ⁻¹ (the non-units mod pᵉ are the multiples of p), we obtain the product formula
φ(n) = n ∏ₚ|ₙ (1 − 1/p).
For example φ(1000) = 1000 · (1/2) · (4/5) = 400 and φ(1001) = φ(7)φ(11)φ(13) = 6 · 10 · 12 = 720.
More generally, for f ∈ ℤ[x], the number of solutions of f(x) ≡ 0 (mod n) is the product of the numbers of solutions modulo the prime powers exactly dividing n. Combined with Hensel's lemma and Lesson 3: x² ≡ 1 (mod pᵉ) has 2 solutions for odd p, while modulo 2, 4 and 2ᵉ (e ≥ 3) it has 1, 2 and 4 solutions. So x² ≡ 1 (mod 840) has 4 · 2 · 2 · 2 = 32 solutions, since 840 = 2³ · 3 · 5 · 7.
The CRT is also a computational principle. In RSA decryption (Lesson 13) one computes modulo p and q separately and recombines, roughly a three- to four-fold saving; computer algebra systems compute determinants and resultants of integer matrices modulo many small primes and recombine them by CRT, avoiding coefficient explosion. Abstractly, the theorem holds in any commutative ring: if ideals I₁, …, Iₖ are pairwise comaximal (Iᵢ + Iⱼ = R), then R/(I₁ ∩ ⋯ ∩ Iₖ) ≅ ∏ R/Iᵢ.
Exercise
- (a)Solve x ≡ 1 (mod 4), x ≡ 2 (mod 5), x ≡ 3 (mod 9).
- (b)How many solutions does x² ≡ 1 (mod 2520) have? (2520 = 2³ · 3² · 5 · 7.)
- (c)Prove that φ(n) is even for every n ≥ 3.
Show solution
Answers: (a) x ≡ 1 (mod 4) and x ≡ 2 (mod 5) give x ≡ 17 (mod 20). Among 17, 37, 57, … the first that is ≡ 3 (mod 9) is 57 (57 = 6 · 9 + 3), so x ≡ 57 (mod 180). (b) 4 · 2 · 2 · 2 = 32. (c) If an odd prime p divides n then p − 1 is an even factor of φ(n). Otherwise n = 2ᵉ with e ≥ 2 and φ(n) = 2ᵉ⁻¹ is even. (Alternatively, a ↦ n − a is a fixed-point-free involution of the units when n ≥ 3.)