Overview

Modular arithmetic is one of the most important tools in olympiad mathematics. It allows us to work with remainders instead of entire numbers, often turning complicated expressions into manageable computations.

Many problems involving:

  • Divisibility
  • Last digits
  • Cyclic patterns
  • Parity
  • Residues
  • Number theoretic equations

and more become a lot simpler when viewed modulo some integer.

The main idea is that two integers are considered equivalent if they leave the same remainder when divided by a fixed modulus.

Motivation

Suppose we want to determine the last digit of

72026.7^{2026}.

Computing the entire number is impossible by hand. However, the last digit of a number depends only on its remainder modulo 1010. As such, we can work modulo 1010:

71≡7(mod10)7^1 \equiv 7 \pmod{10}
72=49≡9(mod10)7^2 = 49 \equiv 9 \pmod{10}
73≡(7)(9)=63≡3(mod10)7^3 \equiv (7)(9) = 63 \equiv 3 \pmod{10}
74≡(7)(3)=21≡1(mod10)7^4 \equiv (7)(3) = 21 \equiv 1 \pmod{10}

The powers repeat with period 44:

7,9,3,1,7,9,3,1,…7,9,3,1,7,9,3,1,\ldots

Since

2026≡2(mod4),2026 \equiv 2 \pmod{4},

the last digit matches that of 727^2, namely 99.

Instead of handling a very large number directly, modular arithmetic reduced the problem to studying a short repeating cycle.

Congruences

Definition

Let mm be a positive integer. We say that

a≡b(modm)a \equiv b \pmod{m}

if aa and bb leave the same remainder when divided by mm.

Equivalently,

m∣(a−b).m \mid (a-b).

In words, a−ba-b is divisible by mm.

Examples

17≡5(mod12)17 \equiv 5 \pmod{12}

because 17−5=1217-5=12 is divisible by 1212.

38≡2(mod9)38 \equiv 2 \pmod{9}

because 38−2=3638-2=36 is divisible by 99.

Negative numbers also work:

−3≡4(mod7)-3 \equiv 4 \pmod{7}

since

−3−4=−7.-3-4=-7.

Residue Classes

Modulo mm, every integer belongs to one of the residue classes

0,1,2,…,m−1.0,1,2,\ldots,m-1.

For example, modulo 55:

  • 12≡2(mod5)12 \equiv 2 \pmod{5}
  • 27≡2(mod5)27 \equiv 2 \pmod{5}
  • 102≡2(mod5)102 \equiv 2 \pmod{5}

so all three numbers belong to the same residue class.

You can think of modular arithmetic as a number system that 'wraps around' after reaching the modulus.

For instance, modulo 1212 behaves like a clock

  • 10+5≡3(mod12)10+5 \equiv 3 \pmod{12}
  • 11+4≡3(mod12)11+4 \equiv 3 \pmod{12}

because after passing 1212, we begin again at 00.

Basic Properties

If

a≡b(modm)a \equiv b \pmod{m}

and

c≡d(modm),c \equiv d \pmod{m},

then:

Addition

a+c≡b+d(modm)a+c \equiv b+d \pmod{m}

Subtraction

a−c≡b−d(modm)a-c \equiv b-d \pmod{m}

Multiplication

ac≡bd(modm)ac \equiv bd \pmod{m}

Powers

ak≡bk(modm)a^k \equiv b^k \pmod{m}

for all positive integers kk.

These rules allow us to simplify expressions significantly before computing.

Important Warning: Division

In ordinary arithmetic, we can cancel common factors freely:

6x=6y  ⟹  x=y.6x = 6y \implies x=y.

In modular arithmetic, cancellation requires more thought.

For example,

(2)(1)≡(2)(4)(mod6)(2)(1) \equiv (2)(4) \pmod{6}

since both sides equal 22 modulo 66.

However,

1≢4(mod6).1 \not\equiv 4 \pmod{6}.

We can only divide by a number if it is coprime to the modulus.

Cancellation Rule

If

ac≡bc(modm)ac \equiv bc \pmod{m}

and

gcd⁡(c,m)=1,\gcd(c,m)=1,

then

a≡b(modm).a \equiv b \pmod{m}.

This idea appears frequently in olympiad problems.

Modular Inverses

Closely related to cancellation is the idea of a modular inverse. We say that aa has a multiplicative inverse modulo mm if there exists an integer bb such that ab≡1(modm)ab \equiv 1 \pmod{m}. This inverse exists if and only if gcd⁡(a,m)=1\gcd(a,m)=1, a fact following from Bézout's identity. When it does exist, dividing by aa modulo mm means multiplying by bb.

Working with Large Numbers

A major advantage of modular arithmetic is that we can reduce numbers at every step.

For example,

13100(mod5).13^{100} \pmod{5}.

Since

13≡3(mod5),13 \equiv 3 \pmod{5},

we instead compute

3100(mod5).3^{100} \pmod{5}.

Now notice:

32=9≡−1(mod5).3^2=9 \equiv -1 \pmod{5}.

Therefore

3100=(32)50≡(−1)50=1(mod5).3^{100} = (3^2)^{50} \equiv (-1)^{50}=1 \pmod{5}.

Hence

13100≡1(mod5).13^{100} \equiv 1 \pmod{5}.

Cyclicity

Powers modulo mm often repeat in cycles. Since there are only finitely many possible residues modulo mm, repeated multiplication must eventually produce a repeated residue.

Example

Find the last digit of

2100.2^{100}.

The powers of 22 modulo 1010 are:

2,4,8,6,2,4,8,6,…2,4,8,6,2,4,8,6,\ldots

The cycle length is 44.

Since

100≡0(mod4),100 \equiv 0 \pmod{4},

the last digit corresponds to the fourth term in the cycle:

6.6.

Recognising cyclic behaviour is one of the most common uses of modular arithmetic in AMC and AIME problems.

Divisibility Tests

Many familiar divisibility rules come naturally from modular arithmetic.

Let

N=a1a2⋯an‾N = \overline{a_1a_2\cdots a_n}

be a positive integer.

Since

N=a1(10n−1)+a2(10n−2)+⋯+an,N = a_1(10^{n-1})+a_2(10^{n-2})+\cdots+a_n,

we can analyse NN modulo different integers.

Divisibility by 22

Because

10≡0(mod2),10 \equiv 0 \pmod{2},

all powers of 1010 beyond the units digit disappear modulo 22.

So only the final digit matters.

Divisibility by 33

Since

10≡1(mod3),10 \equiv 1 \pmod{3},

we have

10k≡1(mod3)10^k \equiv 1 \pmod{3}

for all kk. Therefore,

N≡a1+a2+⋯+an(mod3).N \equiv a_1+a_2+\cdots+a_n \pmod{3}.

Hence a number is divisible by 33 when its digit sum is divisible by 33.

Divisibility by 99

The same argument works because

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

Divisibility by 1111

Since

10≡−1(mod11),10 \equiv -1 \pmod{11},

we get

N≡a1−a2+a3−a4+⋯(mod11).N \equiv a_1-a_2+a_3-a_4+\cdots \pmod{11}.

As such, a number is divisible by 1111 when the alternating digit sum is a multiple of 1111.

Solving Congruences

Linear Congruences

Consider

3x≡5(mod7).3x \equiv 5 \pmod{7}.

We want a multiplicative inverse of 33 modulo 77.

Since

(3)(5)=15≡1(mod7),(3)(5) = 15 \equiv 1 \pmod{7},

multiplying both sides by 55 gives

x≡25≡4(mod7).x \equiv 25 \equiv 4 \pmod{7}.

Thus

x≡4(mod7).x \equiv 4 \pmod{7}.

Key Olympiad Insight

Modular arithmetic is powerful because it allows us to:

  • Eliminate impossible cases
  • Reduce very large computations
  • Classify numbers into residue classes
  • Detect patterns and cycles
  • Prove divisibility or non divisibility.

In many olympiad problems, choosing the correct modulus is the main challenge.

A good heuristic is:

  • Use modulo 22 for parity
  • Modulo 1010 for last digits
  • Modulo 33 or 99 for digit sums
  • Modulo primes for divisibility and residues
  • Modulo small numbers to simplify expressions

Worked Examples

Example 1

Find the remainder when 320263^{2026} is divided by 77.

The powers of 33 modulo 77 cycle:

3,2,6,4,5,1.3,2,6,4,5,1.

The cycle length is 66.

Since

2026≡4(mod6),2026 \equiv 4 \pmod{6},

we get

32026≡34≡4(mod7).3^{2026} \equiv 3^4 \equiv 4 \pmod{7}.

Hence the remainder is 44.

Example 2

Prove that no perfect square leaves remainder 22 when divided by 44.

Every integer is congruent to one of 0,1,2,30,1,2,3 modulo 44.

Squaring each possibility gives:

02≡0(mod4)0^2 \equiv 0 \pmod{4}
12≡1(mod4)1^2 \equiv 1 \pmod{4}
22≡0(mod4)2^2 \equiv 0 \pmod{4}
32≡1(mod4).3^2 \equiv 1 \pmod{4}.

Therefore every square is congruent to either 00 or 11 modulo 44, never 22.

Example 3

Determine the last two digits of 72227^{222}.

We work modulo 100100.

Observe:

74=2401≡1(mod100).7^4 = 2401 \equiv 1 \pmod{100}.

Then

7222=(74)55(72).7^{222} = (7^4)^{55}(7^2).

Therefore,

7222≡(155)(49)≡49(mod100).7^{222} \equiv (1^{55})(49) \equiv 49 \pmod{100}.

Common Pitfalls

  • Forgetting that congruence means equality of remainders, not ordinary equality.
  • Cancelling factors modulo mm when the factor is not coprime to mm.
  • Reducing incorrectly after exponentiation.
  • Using a modulus that does not actually simplify the problem.
  • Assuming patterns continue without proof.

Strategy Tips

  • Reduce numbers modulo mm as early as possible.
  • Search for cycles in powers.
  • Test small cases to identify residue patterns.
  • Use negative residues when convenient:
19≡−1(mod10)19 \equiv -1 \pmod{10}

is often easier to work with than 19≡9(mod10)19 \equiv 9 \pmod{10}.

  • When proving impossibility, try looking at all residue classes modulo a small integer.

Practice Problems

StatusSourceProblem NameDifficultyTags
Berkeley Math CircleHard
Show TagsDivisibility / Factorization, Integers, Modular Arithmetic, Sums and products
Berkeley Math Circle Monthly Contest 1Hard
Show TagsIntegers, Modular Arithmetic
Berkeley Math Circle Monthly Contest 7Hard
Show TagsModular Arithmetic, Prime numbers
Berkeley Math Circle Monthly Contest 5Hard
Show TagsModular Arithmetic, Multiplicative order
Berkeley Math CircleHard
Show TagsIntegers, Modular Arithmetic
Berkeley Math Circle Monthly Contest 3Hard
Show TagsModular Arithmetic, Prime numbers
Berkeley Math CircleHard
Show TagsAlgebraic properties of binomial coefficients, Induction / smoothing, Modular Arithmetic
Berkeley Math Circle Monthly Contest 4Hard
Show TagsModular Arithmetic, Prime numbers
Berkeley Math Circle Monthly Contest 1Hard
Show TagsModular Arithmetic, Prime numbers
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities
Berkeley Math Circle: Monthly Contest 6Hard
Show TagsInvariants / monovariants, Modular Arithmetic
Berkeley Math Circle Monthly Contest 2Hard
Show TagsModular Arithmetic, Quadratic residues
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsInvariants / monovariants, Modular Arithmetic
Berkeley Math Circle Monthly Contest 6Hard
Show TagsDivisibility / Factorization, Modular Arithmetic
Berkeley Math Circle: Monthly Contest 4Hard
Show TagsModular Arithmetic, Recurrence relations
Berkeley Math Circle Monthly Contest 8Hard
Show TagsInduction / smoothing, Modular Arithmetic, Recurrence relations, Recursion, bijection
Berkeley Math CircleHard
Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities
Berkeley Math Circle: Monthly Contest 6Hard
Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities
Berkeley Math Circle Monthly Contest 3Hard
Show TagsModular Arithmetic, Recurrence relations
Berkeley Math Circle Monthly Contest 8Hard
Show TagsModular Arithmetic, Quadratic forms, Techniques: modulo, size analysis, order analysis, inequalities
Berkeley Math CircleHard
Show TagsFactorization techniques, Greatest common divisors (gcd), Modular Arithmetic, Multiplicative order, Quadratic residues, Techniques: modulo, size analysis, order analysis, inequalities
BAMOHard
Show TagsModular Arithmetic
Harvard-MIT Math TournamentHard
Show TagsModular Arithmetic
Berkeley Math CircleHard
Show TagsModular Arithmetic, Pigeonhole principle, Quadratic residues
Harvard-MIT Math TournamentHard
Show TagsModular Arithmetic, Multiplicative order

Module Progress:

Join the Discord Community!

Stuck on a problem, or don't understand a module? Join the Discord and get help with your doubts while making more math friends.