Skip to content
Part IA Michaelmas, Lent Term

Modular Arithmetic

Congruence Modulo nn

Definition

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

n(ab)n \mid (a - b)

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

Examples

  • 175(mod12)17 \equiv 5 \pmod{12} since 175=1217 - 5 = 12 and 121212 \mid 12
  • 232(mod7)23 \equiv 2 \pmod{7} since 232=2123 - 2 = 21 and 7217 \mid 21
  • 53(mod8)-5 \equiv 3 \pmod{8} since 53=8-5 - 3 = -8 and 888 \mid -8

Congruence is an Equivalence Relation

Reflexivity

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

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

Symmetry

ab(modn)ba(modn)a \equiv b \pmod{n} \Rightarrow b \equiv a \pmod{n}

Since n(ab)n \mid (a - b) implies n(ba)n \mid (b - a).

Transitivity

ab(modn)bc(modn)ac(modn)a \equiv b \pmod{n} \land b \equiv c \pmod{n} \Rightarrow a \equiv c \pmod{n}

Proof: n(ab)n \mid (a - b) and n(bc)n \mid (b - c) implies n[(ab)+(bc)]=acn \mid [(a-b) + (b-c)] = a - c.

Congruence Classes

The congruence class of aa modulo nn is:

[a]n={bZ:ab(modn)}={a+kn:kZ}[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,,[n1]n[0]_n, [1]_n, \ldots, [n-1]_n.

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

Arithmetic Operations on Congruences

Addition

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

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

Multiplication

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

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

Powers

If ab(modn)a \equiv b \pmod{n}, then for any k0k \geq 0:

akbk(modn)a^k \equiv b^k \pmod{n}

Proof (Multiplication)

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

acbd=acbc+bcbd=c(ab)+b(cd)ac - bd = ac - bc + bc - bd = c(a - b) + b(c - d)

Since n(ab)n \mid (a - b) and n(cd)n \mid (c - d), we have n[c(ab)+b(cd)]=acbdn \mid [c(a-b) + b(c-d)] = ac - bd.

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

Common Pitfall: Cancellation

The Problem

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

Counterexample

2320(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 acbc(modn)ac \equiv bc \pmod{n}, then ab(modn)a \equiv b \pmod{n}.

Proof: acbc(modn)ac \equiv bc \pmod{n} means nc(ab)n \mid c(a - b).

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

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

Divisibility Tests

Test for 2

akak1a1a0|\overline{a_k a_{k-1} \ldots a_1 a_0}| is divisible by 2 iff a0a_0 (the last digit) is even.

Reason: 100(mod2)10 \equiv 0 \pmod{2}, so ak10k++a110+a0a0(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: 101(mod3)10 \equiv 1 \pmod{3}, so ak10k++a110+a0ak++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: 101(mod9)10 \equiv 1 \pmod{9}.

Test for 11

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

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


Summary

  • ab(modn)a \equiv b \pmod{n} iff n(ab)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