Home / Learn / Modular arithmetic made simple
Learn

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

  1. Reduce as you go. You may take the remainder at any step: (a × b) mod m = ((a mod m) × (b mod m)) mod m.
  2. Fermat’s little theorem. If p is prime and does not divide a, then ap−1 ≡ 1 (mod p). So an exponent can be reduced modulo p−1.
  3. Euler’s theorem. If gcd(a, m) = 1 then aφ(m) ≡ 1 (mod m), where φ(m) counts the numbers up to m that share no factor with m.

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 m instead of modulo φ(m) (or p−1).
  • Using Fermat or Euler when a and m share 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.