Key idea of this section
a ≡ b (mod n) ⟺ n | a − b. ℤ/nℤ = ℤ/(n) is a commutative ring.
(ℤ/nℤ)× = {[a] : gcd(a, n) = 1} has φ(n) elements, and aφ(n) ≡ 1 when gcd(a, n) = 1.
If gcd(m, n) = 1 then ℤ/mnℤ ≅ ℤ/mℤ × ℤ/nℤ (Chinese remainder theorem).The quotient ring
Congruence modulo n ≥ 1 was introduced by Gauss in the Disquisitiones (1801), along with the notation ≡. It is the equivalence relation on ℤ whose classes are the cosets a + nℤ of the ideal nℤ; the set of classes is the quotient ring ℤ/nℤ. Operations on classes are well defined because nℤ is an ideal: if a ≡ a′ and b ≡ b′ then a + b ≡ a′ + b′ and
ab − a′b′ = a(b − b′) + b′(a − a′) ≡ 0 (mod n).
By the division algorithm each class contains exactly one of 0, 1, …, n − 1, so ℤ/nℤ has n elements. The quotient map ℤ → ℤ/nℤ is the unique ring homomorphism of Theorem 3.4, and its kernel is nℤ.
Units, zero divisors and fields
Theorem 7.1. In ℤ/nℤ the class [a] is a unit if and only if gcd(a, n) = 1. Every nonzero class is either a unit or a zero divisor. Consequently ℤ/nℤ is a field if and only if n is prime.
Proof. If gcd(a, n) = 1, Bézout gives ax + ny = 1, so [a][x] = [1]. If d = gcd(a, n) > 1 and [a] ≠ 0, then [a] · [n/d] = [a/d] · [n] = 0 with [n/d] ≠ 0, so [a] is a zero divisor, and zero divisors are never units. If n = p is prime, every a with p ∤ a satisfies gcd(a, p) = 1. If n = rs with 1 < r, s < n, then [r][s] = 0 exhibits zero divisors. ∎
Worked Example 7.2 — the inverse of 17 modulo 43. The Euclidean algorithm gives 43 = 2·17 + 9, 17 = 1·9 + 8, 9 = 1·8 + 1. Back-substituting,
1 = 9 − 8 = 9 − (17 − 9) = 2·9 − 17 = 2(43 − 2·17) − 17 = 2·43 − 5·17
so 17⁻¹ ≡ −5 ≡ 38 (mod 43). Check: 17 · 38 = 646 = 15 · 43 + 1.
Euler's theorem
The unit group (ℤ/nℤ)× has order φ(n), Euler's totient: the number of 1 ≤ a ≤ n with gcd(a, n) = 1.
Theorem 7.3 (Euler, 1763; Fermat, 1640). If gcd(a, n) = 1 then aφ(n) ≡ 1 (mod n). In particular, for p prime and p ∤ a, ap−1 ≡ 1 (mod p), and ap ≡ a (mod p) for every a.
Proof. By Lagrange's theorem the order of [a] in the finite group (ℤ/nℤ)× divides the order φ(n) of the group. ∎
A direct proof avoiding group theory: multiplication by [a] permutes the φ(n) units, so the product of all units equals aφ(n) times itself, and cancelling the (invertible) product gives the result. The multiplicative order ordₙ(a) is the least k ≥ 1 with aᵏ ≡ 1; it divides φ(n), and a is a primitive root modulo n when ordₙ(a) = φ(n). Primitive roots exist exactly for n = 1, 2, 4, pᵏ and 2pᵏ with p an odd prime (Gauss); in particular (ℤ/pℤ)× is cyclic.
Theorem 7.4 (Chinese remainder theorem). If m and n are coprime, the map ℤ/mnℤ → ℤ/mℤ × ℤ/nℤ, [x] ↦ ([x]ₘ, [x]ₙ), is a ring isomorphism.
Proof. The map is a well-defined homomorphism. If x ≡ 0 modulo both m and n then mn | x since gcd(m, n) = 1, so the map is injective, and both sides have mn elements. Explicitly, with mu + nv = 1, the solution of x ≡ a (mod m), x ≡ b (mod n) is x = a·nv + b·mu. ∎
The isomorphism restricts to the unit groups, giving the multiplicativity φ(mn) = φ(m)φ(n) for coprime m, n, and hence
φ(n) = n · ∏ (p | n) (1 − 1/p).
For instance φ(1000) = 1000 · (1/2) · (4/5) = 400 and φ(360) = 360 · (1/2)(2/3)(4/5) = 96. The theorem is named after a problem in the Sunzi Suanjing (c. 3rd–5th century AD): a number leaves remainders 2, 3, 2 on division by 3, 5, 7; the least such number is 23.
Fast exponentiation
To compute aᵉ mod n, write e in binary and square repeatedly; this uses at most 2⌊log₂ e⌋ multiplications modulo n. For 5¹¹⁷ mod 23, with 117 = 1110101₂ = 64 + 32 + 16 + 4 + 1:
5¹ ≡ 5, 5² ≡ 2, 5⁴ ≡ 4, 5⁸ ≡ 16, 5¹⁶ ≡ 3, 5³² ≡ 9, 5⁶⁴ ≡ 12 (mod 23) 5¹¹⁷ ≡ 12 · 9 · 3 · 4 · 5 ≡ 16 · 3 · 4 · 5 ≡ 2 · 4 · 5 ≡ 40 ≡ 17 (mod 23)
Fermat's theorem gives a check: 117 ≡ 7 (mod 22), and 5⁷ = 5⁴ · 5² · 5 ≡ 4 · 2 · 5 = 40 ≡ 17.
Fast exponentiation and Euler's theorem together make the RSA cryptosystem (Rivest, Shamir and Adleman, 1977) work. Choose primes p, q, let n = pq, and choose e coprime to φ(n) with inverse d modulo φ(n). Then (mᵉ)ᵈ ≡ m (mod n) for every m. In the textbook example p = 61, q = 53, n = 3233, φ(n) = 3120, e = 17 and d = 2753 (since 17 · 2753 = 46801 = 15 · 3120 + 1); the message m = 65 encrypts to 65¹⁷ mod 3233 = 2790, and 2790²⁷⁵³ mod 3233 = 65.
Theorem 7.5 (Wilson). An integer p ≥ 2 is prime if and only if (p − 1)! ≡ −1 (mod p).
Proof. If p is prime, in the field ℤ/pℤ each element of {1, …, p − 1} pairs with its inverse; only ±1 are self-inverse (x² = 1 means (x − 1)(x + 1) = 0), so the product is 1 · (−1) = −1. If p = ab is composite with 1 < a < p, then a divides (p − 1)!, so (p − 1)! ≡ 0 ≢ −1 (mod a), and hence (p − 1)! ≢ −1 (mod p). ∎
Exercise
- (a)Find the inverse of 11 modulo 60.
- (b)Solve x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7).
- (c)Compute 3¹⁰⁰ mod 7 and 2¹⁰⁰⁰ mod 13.
Show solution
Answers: (a) 60 = 5·11 + 5, 11 = 2·5 + 1, so 1 = 11 − 2·5 = 11 − 2(60 − 5·11) = 11·11 − 2·60. Hence 11⁻¹ ≡ 11 (mod 60); check 121 = 2·60 + 1. (b) x ≡ 2 (mod 21), since 2 satisfies both the conditions modulo 3 and 7, so x ∈ {2, 23, 44, …}; 23 ≡ 3 (mod 5). The solution is x ≡ 23 (mod 105). (c) 3⁶ ≡ 1 (mod 7) and 100 = 16·6 + 4, so 3¹⁰⁰ ≡ 3⁴ = 81 ≡ 4. 2¹² ≡ 1 (mod 13) and 1000 = 83·12 + 4, so 2¹⁰⁰⁰ ≡ 2⁴ = 16 ≡ 3.