Skip to content
Part IA Michaelmas, Lent Term

Modular Arithmetic

Congruence Modulo nn

Definition

For integers a,ba, b and a positive integer n≥1n \geq 1, we say aa is congruent to bb modulo nn, written a≡b(modn)a \equiv b \pmod{n}, if and only if:

n∣(a−b)n \mid (a - b)

Equivalently, a≡b(modn)a \equiv b \pmod{n} iff aa and bb have the same remainder when divided by nn.

Examples

  • 17≡5(mod12)17 \equiv 5 \pmod{12} since 17−5=1217 - 5 = 12 and 12∣1212 \mid 12
  • 23≡2(mod7)23 \equiv 2 \pmod{7} since 23−2=2123 - 2 = 21 and 7∣217 \mid 21
  • −5≡3(mod8)-5 \equiv 3 \pmod{8} since −5−3=−8-5 - 3 = -8 and 8∣−88 \mid -8

Congruence is an Equivalence Relation

Reflexivity

a≡a(modn)a \equiv a \pmod{n}

Since n∣(a−a)=0n \mid (a - a) = 0 for all nn.

Symmetry

a≡b(modn)⇒b≡a(modn)a \equiv b \pmod{n} \Rightarrow b \equiv a \pmod{n}

Since n∣(a−b)n \mid (a - b) implies n∣(b−a)n \mid (b - a).

Transitivity

a≡b(modn)∧b≡c(modn)⇒a≡c(modn)a \equiv b \pmod{n} \land b \equiv c \pmod{n} \Rightarrow a \equiv c \pmod{n}

Proof: n∣(a−b)n \mid (a - b) and n∣(b−c)n \mid (b - c) implies n∣[(a−b)+(b−c)]=a−cn \mid [(a-b) + (b-c)] = a - c.

Congruence Classes

The congruence class of aa modulo nn is:

[a]n={b∈Z:a≡b(modn)}={a+kn:k∈Z}[a]_n = \{b \in \mathbb{Z} : a \equiv b \pmod{n}\} = \{a + kn : k \in \mathbb{Z}\}

Examples

  • [0]3={…,−6,−3,0,3,6,9,…}[0]_3 = \{\ldots, -6, -3, 0, 3, 6, 9, \ldots\}
  • [1]3={…,−5,−2,1,4,7,10,…}[1]_3 = \{\ldots, -5, -2, 1, 4, 7, 10, \ldots\}
  • [2]3={…,−4,−1,2,5,8,11,…}[2]_3 = \{\ldots, -4, -1, 2, 5, 8, 11, \ldots\}

Number of Classes

There are exactly nn congruence classes modulo nn: [0]n,[1]n,…,[n−1]n[0]_n, [1]_n, \ldots, [n-1]_n.

The standard representatives are Zn={0,1,2,…,n−1}\mathbb{Z}_n = \{0, 1, 2, \ldots, n-1\}.

Arithmetic Operations on Congruences

Addition

If a≡b(modn)a \equiv b \pmod{n} and c≡d(modn)c \equiv d \pmod{n}, then:

a+c≡b+d(modn)a + c \equiv b + d \pmod{n}

Multiplication

If a≡b(modn)a \equiv b \pmod{n} and c≡d(modn)c \equiv d \pmod{n}, then:

ac≡bd(modn)ac \equiv bd \pmod{n}

Powers

If a≡b(modn)a \equiv b \pmod{n}, then for any k≥0k \geq 0:

ak≡bk(modn)a^k \equiv b^k \pmod{n}

Proof (Multiplication)

Given a≡b(modn)a \equiv b \pmod{n} and c≡d(modn)c \equiv d \pmod{n}:

ac−bd=ac−bc+bc−bd=c(a−b)+b(c−d)ac - bd = ac - bc + bc - bd = c(a - b) + b(c - d)

Since n∣(a−b)n \mid (a - b) and n∣(c−d)n \mid (c - d), we have n∣[c(a−b)+b(c−d)]=ac−bdn \mid [c(a-b) + b(c-d)] = ac - bd.

Thus ac≡bd(modn)ac \equiv bd \pmod{n}.

Common Pitfall: Cancellation

The Problem

ac≡bc(modn)⇏a≡b(modn)ac \equiv bc \pmod{n} \not\Rightarrow a \equiv b \pmod{n}

Counterexample

2⋅3≡2⋅0(mod6)2 \cdot 3 \equiv 2 \cdot 0 \pmod{6} but 3≢0(mod6)3 \not\equiv 0 \pmod{6}.

When Does Cancellation Work?

If gcd⁡(c,n)=1\gcd(c, n) = 1 and ac≡bc(modn)ac \equiv bc \pmod{n}, then a≡b(modn)a \equiv b \pmod{n}.

Proof: ac≡bc(modn)ac \equiv bc \pmod{n} means n∣c(a−b)n \mid c(a - b).

Since gcd⁡(c,n)=1\gcd(c, n) = 1, Euclid’s lemma gives n∣(a−b)n \mid (a - b).

Thus a≡b(modn)a \equiv b \pmod{n}.

Divisibility Tests

Test for 2

∣akak−1…a1a0‾∣|\overline{a_k a_{k-1} \ldots a_1 a_0}| is divisible by 2 iff a0a_0 (the last digit) is even.

Reason: 10≡0(mod2)10 \equiv 0 \pmod{2}, so ak⋅10k+⋯+a1⋅10+a0≡a0(mod2)a_k \cdot 10^k + \cdots + a_1 \cdot 10 + a_0 \equiv a_0 \pmod{2}.

Test for 3

A number is divisible by 3 iff the sum of its digits is divisible by 3.

Reason: 10≡1(mod3)10 \equiv 1 \pmod{3}, so ak⋅10k+⋯+a1⋅10+a0≡ak+⋯+a0(mod3)a_k \cdot 10^k + \cdots + a_1 \cdot 10 + a_0 \equiv a_k + \cdots + a_0 \pmod{3}.

Test for 9

A number is divisible by 9 iff the sum of its digits is divisible by 9.

Reason: 10≡1(mod9)10 \equiv 1 \pmod{9}.

Test for 11

A number is divisible by 11 iff the alternating sum of digits (a0−a1+a2−⋯ )(a_0 - a_1 + a_2 - \cdots) is divisible by 11.

Reason: 10≡−1(mod11)10 \equiv -1 \pmod{11}.


Summary

  • a≡b(modn)a \equiv b \pmod{n} iff n∣(a−b)n \mid (a - b)
  • Congruence is an equivalence relation
  • Congruences preserve addition and multiplication
  • Cancellation requires gcd⁡(c,n)=1\gcd(c, n) = 1
  • Divisibility tests use modular arithmetic