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
Computing the entire number is impossible by hand. However, the last digit of a number depends only on its remainder modulo . As such, we can work modulo :
The powers repeat with period :
Since
the last digit matches that of , namely .
Instead of handling a very large number directly, modular arithmetic reduced the problem to studying a short repeating cycle.
Congruences
Definition
Let be a positive integer. We say that
if and leave the same remainder when divided by .
Equivalently,
In words, is divisible by .
Examples
because is divisible by .
because is divisible by .
Negative numbers also work:
since
Residue Classes
Modulo , every integer belongs to one of the residue classes
For example, modulo :
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 behaves like a clock
because after passing , we begin again at .
Basic Properties
If
and
then:
Addition
Subtraction
Multiplication
Powers
for all positive integers .
These rules allow us to simplify expressions significantly before computing.
Important Warning: Division
In ordinary arithmetic, we can cancel common factors freely:
In modular arithmetic, cancellation requires more thought.
For example,
since both sides equal modulo .
However,
We can only divide by a number if it is coprime to the modulus.
Cancellation Rule
If
and
then
This idea appears frequently in olympiad problems.
Modular Inverses
Closely related to cancellation is the idea of a modular inverse. We say that has a multiplicative inverse modulo if there exists an integer such that . This inverse exists if and only if , a fact following from Bézout's identity. When it does exist, dividing by modulo means multiplying by .
Working with Large Numbers
A major advantage of modular arithmetic is that we can reduce numbers at every step.
For example,
Since
we instead compute
Now notice:
Therefore
Hence
Cyclicity
Powers modulo often repeat in cycles. Since there are only finitely many possible residues modulo , repeated multiplication must eventually produce a repeated residue.
Example
Find the last digit of
The powers of modulo are:
The cycle length is .
Since
the last digit corresponds to the fourth term in the cycle:
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
be a positive integer.
Since
we can analyse modulo different integers.
Divisibility by
Because
all powers of beyond the units digit disappear modulo .
So only the final digit matters.
Divisibility by
Since
we have
for all . Therefore,
Hence a number is divisible by when its digit sum is divisible by .
Divisibility by
The same argument works because
Divisibility by
Since
we get
As such, a number is divisible by when the alternating digit sum is a multiple of .
Solving Congruences
Linear Congruences
Consider
We want a multiplicative inverse of modulo .
Since
multiplying both sides by gives
Thus
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 for parity
- Modulo for last digits
- Modulo or for digit sums
- Modulo primes for divisibility and residues
- Modulo small numbers to simplify expressions
Worked Examples
Example 1
Find the remainder when is divided by .
The powers of modulo cycle:
The cycle length is .
Since
we get
Hence the remainder is .
Example 2
Prove that no perfect square leaves remainder when divided by .
Every integer is congruent to one of modulo .
Squaring each possibility gives:
Therefore every square is congruent to either or modulo , never .
Example 3
Determine the last two digits of .
We work modulo .
Observe:
Then
Therefore,
Common Pitfalls
- Forgetting that congruence means equality of remainders, not ordinary equality.
- Cancelling factors modulo when the factor is not coprime to .
- Reducing incorrectly after exponentiation.
- Using a modulus that does not actually simplify the problem.
- Assuming patterns continue without proof.
Strategy Tips
- Reduce numbers modulo as early as possible.
- Search for cycles in powers.
- Test small cases to identify residue patterns.
- Use negative residues when convenient:
is often easier to work with than .
- When proving impossibility, try looking at all residue classes modulo a small integer.
Practice Problems
| Status | Source | Problem Name | Difficulty | Tags | ||
|---|---|---|---|---|---|---|
| Berkeley Math Circle | Hard | Show TagsDivisibility / Factorization, Integers, Modular Arithmetic, Sums and products | ||||
| Berkeley Math Circle Monthly Contest 1 | Hard | Show TagsIntegers, Modular Arithmetic | ||||
| Berkeley Math Circle Monthly Contest 7 | Hard | Show TagsModular Arithmetic, Prime numbers | ||||
| Berkeley Math Circle Monthly Contest 5 | Hard | Show TagsModular Arithmetic, Multiplicative order | ||||
| Berkeley Math Circle | Hard | Show TagsIntegers, Modular Arithmetic | ||||
| Berkeley Math Circle Monthly Contest 3 | Hard | Show TagsModular Arithmetic, Prime numbers | ||||
| Berkeley Math Circle | Hard | Show TagsAlgebraic properties of binomial coefficients, Induction / smoothing, Modular Arithmetic | ||||
| Berkeley Math Circle Monthly Contest 4 | Hard | Show TagsModular Arithmetic, Prime numbers | ||||
| Berkeley Math Circle Monthly Contest 1 | Hard | Show TagsModular Arithmetic, Prime numbers | ||||
| Berkeley Math Circle: Monthly Contest 7 | Hard | Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities | ||||
| Berkeley Math Circle: Monthly Contest 6 | Hard | Show TagsInvariants / monovariants, Modular Arithmetic | ||||
| Berkeley Math Circle Monthly Contest 2 | Hard | Show TagsModular Arithmetic, Quadratic residues | ||||
| Berkeley Math Circle: Monthly Contest 7 | Hard | Show TagsInvariants / monovariants, Modular Arithmetic | ||||
| Berkeley Math Circle Monthly Contest 6 | Hard | Show TagsDivisibility / Factorization, Modular Arithmetic | ||||
| Berkeley Math Circle: Monthly Contest 4 | Hard | Show TagsModular Arithmetic, Recurrence relations | ||||
| Berkeley Math Circle Monthly Contest 8 | Hard | Show TagsInduction / smoothing, Modular Arithmetic, Recurrence relations, Recursion, bijection | ||||
| Berkeley Math Circle | Hard | Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities | ||||
| Berkeley Math Circle: Monthly Contest 6 | Hard | Show TagsModular Arithmetic, Techniques: modulo, size analysis, order analysis, inequalities | ||||
| Berkeley Math Circle Monthly Contest 3 | Hard | Show TagsModular Arithmetic, Recurrence relations | ||||
| Berkeley Math Circle Monthly Contest 8 | Hard | Show TagsModular Arithmetic, Quadratic forms, Techniques: modulo, size analysis, order analysis, inequalities | ||||
| Berkeley Math Circle | Hard | Show TagsFactorization techniques, Greatest common divisors (gcd), Modular Arithmetic, Multiplicative order, Quadratic residues, Techniques: modulo, size analysis, order analysis, inequalities | ||||
| BAMO | Hard | Show TagsModular Arithmetic | ||||
| Harvard-MIT Math Tournament | Hard | Show TagsModular Arithmetic | ||||
| Berkeley Math Circle | Hard | Show TagsModular Arithmetic, Pigeonhole principle, Quadratic residues | ||||
| Harvard-MIT Math Tournament | Hard | 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.
