Lecture 6: Congruences, Part II

William Stein

Math 124 Harvard University Fall 2001

Key Ideas Today

• Wilson’s theorem

• Chinese Remainder Theorem

• Multiplicativity of φ

1 Wilson’s Theorem

Theorem 1.1 (John Wilson’s theorem, from the 1770s). An integer p > 1 is prime if and only if

(p − 1)! ≡ −1 (mod p).

Example 1.2.

? p=3
%1 = 3
? (p-1)! % 3
%2 = 2
? p=17
%3 = 17
? (p-1)!
%4 = 20922789888000
? (p-1)! % p
%5 = 16

Proof. We first assume that p is prime and prove that (p − 1)! ≡ −1 (mod p). If a ∈ {1, 2, …, p − 1} then the equation

ax ≡ 1 (mod p)

has a unique solution a′ ∈ {1, 2, …, p − 1}. If a = a′, then a^{2} ≡ 1 (mod p), so p | a^{2} − 1 = (a − 1)(a + 1), so p | (a − 1) or p | (a + 1), so a ∈ {1, −1}. We can thus pair off the elements of {2, 3, …, p − 2}, each with its inverse. Thus

2 · 3 · · · · · (p − 2) ≡ 1 (mod p).

Multiplying both sides by p − 1 proves that (p − 1)! ≡ −1 (mod p).

Next we assume that (p − 1)! ≡ −1 (mod p) and prove that p must be prime. Suppose not, so that p is a composite number ≥ 4. Let ℓ be a prime divisor of p. Then ℓ < p, so ℓ | (p − 1)!. Also,

ℓ | p | ((p − 1)! − 1).

This is a contradiction, because a prime can’t divide a number a and also divide a − 1, since it would then have to divide a − (a − 1) = 1.

Example 1.3. When p = 17, we have

2 · 3 · · · · · 15 = (2 · 9) · (3 · 6) · (4 · 13) · (5 · 7) · (8 · 15) · (10 · 12) · (14 · 11) ≡ 1 (mod 17),

where we have paired up the numbers a, b for which ab ≡ 1 (mod 17).

Let’s test Wilson’s Theorem in PARI:

? wilson(n) = Mod((n-1)!,n) == Mod(-1,n)
? wilson(5)
%9 = 1
? wilson(10)
%10 = 0
? wilson(389)
%11 = 1
? wilson(2001)
%12 = 0

Warning: In practice, this is a horribly inefficient way to check whether or not a number is prime.

2 The Chinese Remainder Theorem

Sun Tsu Suan-Ching (4th century AD):

There are certain things whose number is unknown. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; and by 7 the remainder is 2. What will be the number?

In modern notation, Sun is asking us to solve the following system of equations:

x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7)

The Chinese Remainder Theorem asserts that a solution to Sun’s question exists, and the proof gives a method to find a solution.

Theorem 2.1 (The Chinese Remainder Theorem). Let a, b ∈ ℤ and n, m ∈ ℕ such that gcd(n, m) = 1. Then there exists x ∈ ℤ such that

x ≡ a (mod m)
x ≡ b (mod n)

Proof. The equation

tm ≡ b − a (mod n)

has a solution t since gcd(m, n) = 1. Set x = a + tm. We next verify that x is a solution to the two equations. Then

x ≡ a + (b − a) ≡ b (mod n),

and

x = a + tm ≡ a (mod m).

Now we can solve Sun’s problem:

x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7).

First, we use the theorem to find a solution to the pair of equations

x ≡ 2 (mod 3)
x ≡ 3 (mod 5).

Set a = 2, b = 3, m = 3, n = 5. Step 1 is to find a solution to t · 3 ≡ 3 − 2 (mod 5). A solution is t = 2. Then x = a + tm = 2 + 2 · 3 = 8. Since any x′ with x′ ≡ x (mod 15) is also a solution to those two equations, we can solve all three equations by finding a solution to the pair of equations

x ≡ 8 (mod 15)
x ≡ 2 (mod 7).

Again, we find a solution to t · 15 ≡ 2 − 8 (mod 7). A solution is t = 1, so

x = a + tm = 8 + 15 = 23.

Note that there are other solutions. Any x′ ≡ x (mod 3 · 5 · 7) is also a solution; e.g., 23 + 3 · 5 · 7 = 128.

We can also solve Sun’s problem in PARI:

? chinese(Mod(2,3),Mod(3,5))
%13 = Mod(8, 15)
? chinese(Mod(8,15),Mod(2,7))
%14 = Mod(23, 105)

3 Multiplicative Functions

Definition 3.1. A function f : ℕ → ℤ is multiplicative if, whenever m, n ∈ ℕ and gcd(m, n) = 1, we have

f(mn) = f(m) · f(n).

Recall that the Euler φ-function is

φ(n) = #{a : 1 ≤ a ≤ n and gcd(a, n) = 1}.

Proposition 3.2. φ is a multiplicative function.

Proof. Suppose that m, n ∈ ℕ and gcd(m, n) = 1. Consider the map

{c : 1 ≤ c ≤ mn and gcd(c, mn) = 1} ⟶^{f}

{a : 1 ≤ a ≤ m and gcd(a, m) = 1} × {b : 1 ≤ b ≤ n and gcd(b, n) = 1}}

defined by

f(c) = (c mod m, c mod n).

The map f is injective: If f(c) = f(c′), then m | c − c′ and n | c − c′, so, since gcd(n, m) = 1, nm | c − c′, so c = c′.

The map f is surjective: Given a, b with gcd(a, m) = 1, gcd(b, n) = 1, the Chinese Remainder Theorem implies that there exists c with c ≡ a (mod m) and c ≡ b (mod n). We may assume that 1 ≤ c ≤ nm, ans since gcd(a, m) = 1 and gcd(b, n) = 1, we must have gcd(c, nm) = 1. Thus f(c) = (a, b).

Because f is a bijection, the set on the left has the same size as the product set on the right. Thus

φ(mn) = φ(m) · φ(n).

Example 3.3. The proposition makes it easier to compute φ(n). For example,

φ(12) = φ(2^{2}) · φ(3) = 2 · 2 = 4.

Also, for n ≥ 1, we have

φ(p^{n}) = p^{n} − \frac{p^{n}}{p} ,

since φ(p^{n}) is the number of numbers less than p^{n} minus the number of those that are divisible by p. Thus, e.g.,

φ(389 · 11^{2}) = 388 · (11^{2} − 11) = 388 · 110 = 42680.

The φ function is also available in PARI:

  ? eulerphi(389*11^2)
  %15 = 42680

Question 3.4. Is computing φ(1000 digit number) really easy or really hard?