Lecture 5: Congruences

William Stein

Math 124 Harvard University Fall 2001

The point of this lecture: Define the ring ℤ/nℤ of integers modulo n. Prove Fermat’s little theorem, which asserts that if gcd(x, n) = 1, then x^{φ(n)} ≡ 1 (mod n).

1 Notation

Definition 1.1 (Congruence). Let a, b ∈ ℤ and n ∈ ℕ. Then

a ≡ b (mod n)

if n | a − b.

That is, there is c ∈ ℤ such that

nc = a − b.

One way I think about it: a is congruent to b modulo n, if we can get from b to a by adding multiples of n.

Congruence modulo n is an equivalence relation. Let

ℤ/nℤ = { the set of equivalence classes }

The set ℤ/nℤ is a ring, the “ring of integers modulo n”. It is the quotient of the ring ℤ by the ideal generated by n. Example 1.2.

ℤ/3ℤ = {{…, −3, 0, 3, …}, {…, −2, 1, 4, …}, {…, −1, 2, 5, …}} = {[0], [1], [2]}

where we let [a] denote the equivalence class of a.

2 Arithmetic Modulo N

Suppose a, a′, b b′ ∈ ℤ and

a ≡ a′ (mod n), b ≡ b′ (mod n).

Then

a + b ≡ a′ + b′ (mod n)  (1)
a × b ≡ a′ × b′ (mod n)  (2)

So it makes sense to define + and × by [a] + [b] = [a + b] and [a] × [b] = [a × b].

2.1 Cancellation

Proposition 2.1. If gcd(c, n) = 1 and

ac ≡ bc (mod n)

then a ≡ b (mod n).

Proof. By definition

n | ac − bc = (a − b)c.

Since gcd(n, c) = 1, it follows that n | a − b, so

a ≡ b (mod n),

as claimed.

2.2 Rules for Divisibility

Proposition 2.2. A number n ∈ ℤ is divisible by 3 if and only if the sum of the digits of n is divisible by 3.

Proof. Write

n = a + 10b + 100c + · · · .

Since 10 ≡ 1 (mod 3),

n = a + 10b + 100c + ⋯ ≡ a + b + c + ⋯ (mod 3),

from which the proposition follows.

Similarly, you can find rules for divisibility by 5, 9 and 11. What about divisibility by 7?

3 Linear Congruences

Definition 3.1 (Complete Set of Residues). A complete set of residues modulo n is a subset R ⊂ ℤ of size n whose reductions modulo n are distinct. In other words, a complete set of residues is a choice of representive for each equivalence class in ℤ/nℤ.

Some examples:

R = {0, 1, 2, …, n − 1}

is a complete set of residues modulo n. When n = 5, a complete set of residues is

R = {0, 1, −1, 2, −2}.

Lemma 3.2. If R is a complete set of residues modulo n and a ∈ ℤ with gcd(a, n) = 1, then aR = {ax : x ∈ R} is also a complete set of residues.

Proof. If ax ≡ ax′ (mod n) with x, x′ ∈ R, then Proposition 2.1 implies that x ≡ x′ (mod n). Because R is a complete set of residues, this implies that x = x′. Thus the elements of aR have distinct reductions modulo n. It follows, since #aR = n, that aR is a complete set of residues modulo n.

Definition 3.3 (Linear Congruence). A linear congruence is an equation of the form

ax ≡ b (mod n).

Proposition 3.4. If gcd(a, n) = 1, then the equation

ax ≡ b (mod n)

must have a solution.

Proof. Let R be a complete set of residues modulo n (for example, R = {0, 1, …, n− 1}). Then by Lemma 3.2, aR is also a complete set of residues. Thus there is an element ax ∈ aR such that ax ≡ b (mod n), which proves the proposition.

The point in the proof is that left multiplication by a defines a map ℤ/nℤ ↪ ℤ/nℤ, which must be surjective because ℤ/nℤ is finite.

Illustration:

2x ≡ 3 (mod 7)

Set R = {0, 1, 2, 3, 4, 5, 6}. Then

2R = {0, 2, 4, 6, 8 ≡ 1, 10 ≡ 3, 12 ≡ 5},

so 2 · 5 ≡ 3 (mod 7).

Warning: Note that the equation ax ≡ b (mod n) might have a solution even if gcd(a, n) ≠ 1. To construct such examples, let a be any divisor of n, x any number, and set b = ax. For example, 2x ≡ 6 (mod 8) has a solution!

4 Fermat’s Little Theorem

Definition 4.1 (Order). Let n ∈ ℕ and x ∈ ℤ with gcd(x, n) = 1. The order of x modulo n is the smallest m ∈ ℕ such that

x^{m} ≡ 1 (mod n).

We must show that this definition makes sense. To do so, we verify that such an m exists. Consider x, x^{2}, x^{3}, … modulo n. There are only finitely many residue classes modulo n, so we must eventually find two integers i, j with i < j such that

x^{i} ≡ x^{j} (mod n).

Since gcd(x, n) = 1, Proposition 2.1 implies that we can cancel x’s and conclude that

x^{j−i} ≡ 1 (mod n).

Definition 4.2 (Euler Phi function). Let

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

For example,

φ(1) = #{1} = 1,
φ(5) = #{1, 2, 3, 4} = 4,
φ(12) = #{1, 5, 7, 11} = 4.

If p is any prime number then

φ(p) = #{1, 2, …, p − 1} = p − 1.

Theorem 4.3 (Fermat’s Little Theorem). If gcd(x, n) = 1, then

x^{φ(n)} ≡ 1 (mod n).

Proof. Let

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

In the same way that we proved Lemma 3.2, we see that the reductions modulo n of the elements of xP are exactly the same as the reductions of the elements of P. Thus

∏_{a∈P}(xa) = ∏_{a∈P} a (mod n),

since the products are over exactly the same numbers modulo n. Now cancel the a’s on both sides to get

x^{#P} ≡ 1 (mod n),

as claimed.

4.1 Group-theoretic Interpretation

The set of invertible elements of ℤ/nℤ is a group

(ℤ/nℤ)^{∗} = {[a] ∈ ℤ/nℤ : gcd(a, n) = 1}.

This group has order φ(n). Theorem 4.3 asserts that the order of an element of (ℤ/nℤ)^{×} divides the order φ(n) of (ℤ/nℤ)^{×}. This is a special case of the more general theorem that if G is a finite group and g ∈ G, then the order of g divide #G.

5 What happened?

Take out a piece of paper and answer the following two questions:

1. What is a central idea that you learned in this lecture?

2. What part of this lecture did you find murky?