Key idea of this section
a has a multiplicative inverse modulo n ⟺ gcd(a, n) = 1.
Congruence
Fix a modulus n ≥ 1. We write a ≡ b (mod n) when n | a − b. This is an equivalence relation, and it respects both ring operations: if a ≡ a' and b ≡ b' then a + b ≡ a' + b' and ab ≡ a'b' (since ab − a'b' = a(b − b') + b'(a − a')). The equivalence classes ā = a + nℤ are the residue classes, and the set of n classes forms a commutative ring ℤ/nℤ, the quotient of ℤ by the ideal nℤ. Gauss introduced the notation ≡ in 1801, deliberately echoing =.
Many classical facts are one-line congruence computations. Since 10 ≡ 1 (mod 9), any number is congruent to its digit sum mod 9; since 10 ≡ −1 (mod 11), it is congruent mod 11 to its alternating digit sum. Since every square is ≡ 0 or 1 (mod 4), no integer ≡ 3 (mod 4) is a sum of two squares. Since every odd square is ≡ 1 (mod 8), no integer ≡ 7 (mod 8) is a sum of three squares (Problem 55 completes this to Legendre's condition).
Units and zero divisors
Theorem 3.1. The class ā is a unit in ℤ/nℤ if and only if gcd(a, n) = 1. If gcd(a, n) = d > 1, then ā is a zero divisor (or zero).
Proof. ā is a unit iff ax ≡ 1 (mod n) is solvable iff ax + ny = 1 is solvable iff gcd(a, n) = 1, by Corollary 1.3. If d > 1, then a · (n/d) = (a/d) · n ≡ 0 while n/d ≢ 0 (mod n). ∎
The units form a group (ℤ/nℤ)× of order φ(n), Euler's totient: the number of integers in {1, …, n} coprime to n. In particular ℤ/nℤ is a field if and only if n is prime; we write 𝔽ₚ for ℤ/pℤ.
Worked example: 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.
Linear congruences
Theorem 3.2. Let d = gcd(a, n). The congruence ax ≡ b (mod n) is solvable if and only if d | b, in which case it has exactly d solutions modulo n, forming a single residue class modulo n/d.
Proof. Solvability is Theorem 1.6 applied to ax − ny = b. If d | b, divide through: (a/d)x ≡ b/d (mod n/d), where a/d is now invertible modulo n/d, giving a unique class x₀ mod n/d. Its lifts x₀ + k(n/d), k = 0, 1, …, d − 1, are distinct mod n. ∎
Worked example: solve 35x ≡ 10 (mod 50). Here d = gcd(35, 50) = 5 divides 10, so there are 5 solutions. Dividing by 5: 7x ≡ 2 (mod 10). Since 7 · 3 = 21 ≡ 1 (mod 10), x ≡ 3 · 2 = 6 (mod 10). Modulo 50 the solutions are x ≡ 6, 16, 26, 36, 46. Check: 35 · 6 = 210 = 4 · 50 + 10.
Polynomial congruences
For a polynomial f ∈ ℤ[x], the number of solutions of f(x) ≡ 0 (mod n) is a basic arithmetic invariant. Over a field the situation is controlled by the following theorem.
Theorem 3.3 (Lagrange). If p is prime and f ∈ ℤ[x] has degree d whose leading coefficient is not divisible by p, then f(x) ≡ 0 (mod p) has at most d solutions modulo p.
Proof. 𝔽ₚ is a field, so 𝔽ₚ[x] has a division algorithm: if f(r) = 0 then f(x) = (x − r)g(x) with deg g = d − 1. If s ≠ r is another root then (s − r)g(s) = 0 in 𝔽ₚ, and since 𝔽ₚ has no zero divisors g(s) = 0. Induction on d completes the proof. ∎
The hypothesis that the modulus is prime is essential: x² ≡ 1 (mod 8) has four solutions 1, 3, 5, 7. For composite moduli one first reduces to prime powers by the Chinese remainder theorem (Lesson 5) and then to primes by Hensel's lemma.
Theorem 3.4 (Hensel's lemma, simple form). Let p be prime, f ∈ ℤ[x], and suppose f(a) ≡ 0 (mod pᵏ) and f'(a) ≢ 0 (mod p), where k ≥ 1. Then there is a unique t modulo p such that f(a + tpᵏ) ≡ 0 (mod pᵏ⁺¹).
Proof. By Taylor expansion (valid over ℤ because f(a + h) − f(a) − f'(a)h is divisible by h², and 2k ≥ k + 1), f(a + tpᵏ) ≡ f(a) + tpᵏ f'(a) (mod pᵏ⁺¹). Writing f(a) = pᵏ m, the condition becomes m + t f'(a) ≡ 0 (mod p), which has exactly one solution t since f'(a) is invertible mod p. ∎
Thus a simple root modulo p lifts uniquely to a root modulo every pᵏ, and in the limit to a root in the p-adic integers ℤₚ. This is Newton's method in the p-adic metric, where |x|ₚ = p−vₚ(x).
Exercise
- (a)Solve 91x ≡ 35 (mod 133).
- (b)Find all solutions of x² ≡ 2 (mod 49).
- (c)Show that x² ≡ 1 (mod 2ᵏ) has exactly four solutions for every k ≥ 3.
Show solution
Answers: (a) gcd(91, 133) = 7 divides 35, so divide by 7: 13x ≡ 5 (mod 19). Since 13 · 3 = 39 ≡ 1 (mod 19), x ≡ 15 (mod 19), and modulo 133 the seven solutions are 15, 34, 53, 72, 91, 110, 129. Check: 91 · 15 = 1365 = 10 · 133 + 35. (b) Modulo 7, x² ≡ 2 has roots ±3. Lift x = 3 + 7t: (3 + 7t)² ≡ 9 + 42t (mod 49), and 9 + 42t ≡ 2 means 42t ≡ −7, i.e. 6t ≡ −1 ≡ 6 (mod 7), so t = 1 and x = 10. The other root is −10 ≡ 39. Check: 100 = 2·49 + 2. (c) x must be odd; (x − 1)(x + 1) ≡ 0 (mod 2ᵏ) with exactly one of x ± 1 divisible by 2 only once (they differ by 2 and both are even), so the other is divisible by 2ᵏ⁻¹. This gives x ≡ ±1 (mod 2ᵏ⁻¹), that is x ≡ 1, 1 + 2ᵏ⁻¹, −1, −1 + 2ᵏ⁻¹ (mod 2ᵏ), four distinct classes when k ≥ 3, and all four do satisfy x² ≡ 1 since (±1 + 2ᵏ⁻¹)² = 1 ± 2ᵏ + 2²ᵏ⁻² ≡ 1 (mod 2ᵏ).