You are on page 1of 4

Lec12: Three Special Congruences

29 Mar 2023, MATH4024-Number Theory, Lecturer: Prof A. Munagi

1 Introduction
We will study the proofs and some applications of the following congruences.

I. (Wilson). If p is prime, then

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

II. (Fermat). If p is prime and a ∈ Z+ with p - a, then

ap−1 ≡ 1 (mod p).

III. (Euler). If a, m ∈ Z+ with (a, m) = 1, then

aφ(m) ≡ 1 (mod m),

where φ(m) = |{x ∈ Z+ | x < m and (x, m) = 1}|.

2 Wilson’s Theorem
Exercise 1. Prove: an integer a is its own inverse modulo a prime p if and only if
a ≡ ±1 (mod p) if and only if a ≡ 1 or p − 1 (mod p).

Wilson’s Theorem was published in 1770 by Edward Waring who attributed it to


his student, John Wilson.

Theorem 2.1 (Wilson’s Theorem). If p is prime, then

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

1
Prof A. Munagi Lec12: Three Special Congruences MATH4024-Number Theory

Proof. If p = 2, then (p − 1)! ≡ 1 ≡ −1 (mod 2). So the theorem holds for p = 2.


Now assume that p is an odd prime (> 2). For each integer with 1 ≤ a ≤ p − 1, ∃
an inverse a, 1 ≤ a ≤ p − 1, with aa ≡ 1 (mod p).
By Exerc. 1 only 1 and p − 1 are their own inverses.
p−3
Therefore we can group the integers 2, 3, . . . , p − 2 into pairs such that the
2
product of each pair is congruent to 1 (mod p). Therefore

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

Multiplying both sides by 1 and p − 1 we obtain

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

Remark. Theorem 2.1 also follows from the fact that Zp = {1, 2, . . . , p − 1} is a
multiplicative (cyclic) group in which every element has an inverse. Since only 1 and
p − 1 are their own inverses in Zp , it follows that

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

Example. Take p = 7. Then (7 − 1)! = 6! = 1 · 2 · ·3 · 4 · 5 · 6. Now rearrange the factors


by pairing each factor with its inverse modulo 7: 2 · 4 ≡ 1, 3 · 5 ≡ 1 (mod 7). This
implies that 6! = 1 · (2 · 4) · (3 · 5) · 6 ≡ 1 · 6 ≡ −1 (mod 7), that is, 6! ≡ −1 (mod 7).

Interestingly the converse of Wilson’s Theorem is also true. We are rewarded with
a primality test.

Theorem 2.2 (Converse of Wilson’s Theorem). If n ≥ 2 is a positive integer such that


(n − 1)! ≡ −1 (mod n), then n is prime.

Proof. Assume that n is composite and

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

Since n is composite ∃ integers a, b with n = ab, where 1 < a < n, 1 < b < n.
Since a < n we have that a|(n − 1)!;
Equation (1) implies that n|((n − 1)! + 1).
But a|n =⇒ a|((n − 1)! + 1).
Now a|(n − 1)! and a|((n − 1)! + 1) implies that a|((n − 1)! + 1 − (n − 1)!) ⇐⇒ a|1.
This is a contradiction because a > 1.
Example. Is the number 6 prime? Using the converse of Wilson’s Theorem we compute

(6 − 1)! = 5! = 120 ≡ 0 6≡ −1 (mod 6).

2
Prof A. Munagi Lec12: Three Special Congruences MATH4024-Number Theory

Hence 6 is not prime.


The Converse of Wilson’s Theorem has only theoretical interest, and is not practical
as a primality test because of the large number of integers to be multiplied together to
reach a decision.

Exercise 2. Use the Converse of Wilson’s Theorem to determine the primality of 13.

3 Fermat’s Little Theorem


The Theorem was first asserted in 1640. Euler published the first proof in 1736, and
subsequently generalized the theorem (see III.)
Theorem 3.1 (Fermat’s Little Theorem). If p is prime and a is a positive integer with
p - a, then
ap−1 ≡ 1 (mod p).
Proof. Consider the p − 1 integers,

a, 2a . . . , (p − 1)a. (2)

None of these integers is divisible by p, for if p|ja, then p|j since p - a. But this is
impossible because 1 ≤ j ≤ p − 1.
Furthermore, no two of the integers are congruent modulo p. To see this, assume that
ja ≡ ka (mod p), where 1 ≤ j < k ≤ p − 1. Then since (a, p) = 1, we obtain j ≡ k
(mod p). But this congruence is impossible because j and k are positive integers < p.
Because the integers in (2) form a set of p − 1 integers all incongruent to 0 modulo
p, and we know that the least positive residue of the seq (2), taken in some order, must
be the integers
1, 2 . . . , (p − 1). (3)
Therefore the product of the integers in (2) is congruent modulo p to the product of
the integers in (3). Hence

a · 2a · · · (p − 1)a ≡ 1 · 2 · · · (p − 1) (mod p)

.
=⇒ ap−1 (p − 1)! ≡ (p − 1)! (mod p).
Since ((p − 1)!, p) = 1, we may cancel (p − 1)! to obtain ap−1 ≡ 1 (mod p).

Example. Since 7 - 3 we have 36 ≡ 1 (mod 7). (Check 36 = 729 = 7 · 104 + 1).

Exercise 3. Use Theorem 3.1 or otherwise to derive the following more complete
Fermat’s Little Theorem:

If p is prime and a ∈ Z+ , then ap ≡ a (mod p).

3
Prof A. Munagi Lec12: Three Special Congruences MATH4024-Number Theory

3.1 Some Applications of Fermat’s Little Theorem


(1) Finding the least positive residue of integer powers. For example,

If 3502 ≡ r (mod 11), where 0 ≤ r < 11, what is r?

p − 1 = 11 − 1 = 10; 502 = 10 · 50 + 2. By Fermat’s Little Theorem we know that


310 ≡ 1 (mod 11). Hence

3502 ≡ (310 )50 · 32 ≡ 32 ≡ 9 (mod 11).

Exercise 4. Let n, k ∈ Z+ such that k = (p − 1)q + r, 0 ≤ r < p.


Prove that nk ≡ nr (mod p).

(2) If p is a prime and a ∈ Z+ such that p - a, then ap−2 is an inverse of a modulo p.


(That is, ax ≡ 1 (mod p) ⇐⇒ x ≡ aa−2 (mod p)).
To see this note that if p - a, then Fermat’s Little Theorem gives

a · ap−2 ≡ ap−1 ≡ 1 (mod p) =⇒ a−1 = ap−2 .

Example, 211−2 = 29 = 512 ≡ 6 (mod 11) is an inverse of 2 modulo 11.


(3) If a, b ∈ Z+ and p is prime with p - a, then the solutions of the linear congruence
ax ≡ b (mod p) are given by x ≡ ap−2 b (mod p).

You might also like