Modular arithmetic made simple
Reduce the numbers before you multiply.
The idea
“a mod m” is the remainder when a is divided by m. Exam questions almost always ask for a huge power or a last digit that you could never compute directly, so the whole skill is shrinking the numbers before you multiply.
Three tools
- Reduce as you go. You may take the remainder at any step:
(a × b) mod m = ((a mod m) × (b mod m)) mod m. - Fermat’s little theorem. If
pis prime and does not dividea, thenap−1 ≡ 1 (mod p). So an exponent can be reduced modulop−1. - Euler’s theorem. If
gcd(a, m) = 1thenaφ(m) ≡ 1 (mod m), whereφ(m)counts the numbers up tomthat share no factor withm.
Worked examples
1. What is 7222 mod 13?
13 is prime, so the exponent can be reduced modulo 12. Since 222 = 12 × 18 + 6, we get 7222 ≡ 76.
Now 72 = 49 ≡ 10, so 73 ≡ 70 ≡ 5 and 76 ≡ 52 = 25 ≡ 12.
Answer: 12
2. What are the last two digits of 3100?
The last two digits mean mod 100. gcd(3, 100) = 1 and φ(100) = 40, so 3100 = 340×2 + 20 ≡ 320.
Square repeatedly: 35 = 243 ≡ 43; 310 ≡ 432 = 1849 ≡ 49; 320 ≡ 492 = 2401 ≡ 01.
Answer: 01
3. Find x with 7x ≡ 1 (mod 26).
Use the Euclidean algorithm: 26 = 3×7 + 5, then 7 = 1×5 + 2, then 5 = 2×2 + 1. Working backwards, 1 = 3×26 − 11×7, so 7 × (−11) ≡ 1.
Add 26 to get a positive value: −11 + 26 = 15. Check: 7 × 15 = 105 = 4 × 26 + 1.
Answer: 15
Common mistakes
- Reducing the exponent modulo
minstead of moduloφ(m)(orp−1). - Using Fermat or Euler when
aandmshare a factor. - Slipping on the small arithmetic. Write every step down.
Practise this topic
Try questions on this topic with instant explanations, or test yourself against the world in the ranked exam.