Number theory
IOQM · All sections · about 7 minutes
Olympiad number theory is about divisibility, primes, remainders and digits. The key tool is modular arithmetic: working only with remainders.
Look for cycles. Last digits of powers repeat, remainders of powers repeat, and once you find the cycle length you can jump straight to a huge power.
Divisibility and prime factors
Every whole number above 1 splits into primes in exactly one way. From n = p^a × q^b × r^c you get everything: the number of divisors (a + 1)(b + 1)(c + 1), whether n is a square (all powers even), and the gcd and lcm of two numbers (smallest and largest powers).
gcd(a, b) × lcm(a, b) = a × b. The Euclidean algorithm finds the gcd fast: gcd(a, b) = gcd(b, a mod b).
Working with remainders
Modular arithmetic keeps only remainders: if a ≡ b (mod m), you can add, subtract and multiply both sides. To find a huge power’s remainder, find a small power that leaves 1 and use cycles.
Fermat’s little theorem: a^(p−1) ≡ 1 (mod p) for a prime p not dividing a. Squares leave only 0 or 1 mod 4 and 0, 1 or 4 mod 8, which kills many equations at once.
Digits and last digits
A number is divisible by 9 exactly when its digit sum is; by 11 when the alternating digit sum is. Last digits of powers cycle with length 1, 2 or 4.
Trailing zeros of n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …, because each zero needs a factor of 5.
Worked examples
Example 1How many trailing zeros does 100! have?
- ⌊100/5⌋ = 20.
- ⌊100/25⌋ = 4.
- ⌊100/125⌋ = 0.
Answer: 24
Example 2Find the remainder when 3¹⁰⁰ is divided by 7.
- 3⁶ ≡ 1 (mod 7) by Fermat.
- 100 = 6 × 16 + 4, so 3¹⁰⁰ ≡ 3⁴ = 81.
- 81 = 7 × 11 + 4.
Answer: 4
Example 3Find the smallest n such that 1260n is a perfect square.
- 1260 = 2² × 3² × 5 × 7.
- The powers of 5 and 7 are odd.
- n = 5 × 7.
Answer: 35
Where marks are lost
- Forgetting ⌊n/25⌋ and higher terms for trailing zeros.
- Using Fermat when the base shares a factor with the prime.
- Counting divisors without the +1 for each power.
Exam tips
- Last digits of 2, 3, 7 and 8 powers repeat every 4.
- Number of divisors of p^a q^b r^c is (a + 1)(b + 1)(c + 1).
- Fermat: aᵖ⁻¹ leaves remainder 1 on division by a prime p (if p does not divide a).
Practice questions
What is the last digit of 7²⁰²⁶?
How many positive divisors does 360 have?
What is the remainder when 2¹⁰⁰ is divided by 7?
More worked examples
Try each one first, then open the working.
Three traffic lights change every 12, 27 and 50 seconds. They all change together at 8:00 a.m. After how many seconds will they next change together?
Show the working
Start: Find the LCM of the three times.
LCM(12, 27, 50) = 2700 s.
Answer: 2700 s
A floor 180 cm by 140 cm is to be covered with the largest possible square tiles, without cutting any. How many tiles are needed?
Show the working
Start: The tile side must divide both lengths: find the HCF.
Largest tile side = HCF(180, 140) = 20 cm. Tiles = (180 ÷ 20) × (140 ÷ 20) = 9 × 7 = 63.
Answer: 63
All the whole numbers from 0 to 31 are written in 5-bit binary. How many 1s are written in total?
Show the working
Start: Count position by position.
Each of the 5 positions is 1 in exactly half of the 32 numbers: 5 × 16 = 80.
Answer: 80
The clock shows the time now. What hour will it show 37 hours later? (Type a number from 1 to 12.)
Show the working
Start: Only the remainder after dividing by 12 matters.
37 = 3 × 12 + 1. Full 12s change nothing, so move 1 hours from 9: 10 o’clock.
Answer: 10
Practise more
New questions every time, at exam level
Three traffic lights change every 12, 36 and 40 seconds. They all change together at 8:00 a.m. After how many seconds will they next change together?
Learn it properly
Full chapters with animations, each with an “Explained simply” version.