Number theory

Number theory studies the whole numbers: divisibility, primes, remainders and the patterns they make. It was once the purest of pure mathematics. Now it secures online payments, because modular arithmetic makes some calculations easy one way and practically impossible to reverse.

Key facts

  • a mod m is the remainder when a is divided by m. a ≡ b (mod m) means m divides a − b.
  • Euclidean algorithm: gcd(a, b) = gcd(b, a mod b). Repeat until the remainder is 0.
  • Bézout: there are integers x and y with ax + by = gcd(a, b). So a has an inverse mod m exactly when gcd(a, m) = 1.
  • If n = pᵃ × qᵇ (p, q prime), n has (a + 1)(b + 1) positive divisors.
  • Fermat’s little theorem: if p is prime and does not divide a, then a^(p−1) ≡ 1 (mod p).
  • lcm(a, b) = ab ÷ gcd(a, b).

Worked examples

Example 1

Use the Euclidean algorithm to find gcd(252, 198), and hence find lcm(252, 198).

  1. Divide 252 by 198. 252 = 1 × 198 + 54
  2. Divide 198 by the remainder, 54. 198 = 3 × 54 + 36
  3. Keep going until the remainder is 0. The gcd is 18. 54 = 1 × 36 + 18, 36 = 2 × 18 + 0
  4. lcm = product ÷ gcd: (252 × 198)/18 = 2,772

Answer: gcd 18, lcm 2,772

Example 2

Find the last digit of 7²⁰²⁶.

  1. The last digits of 7, 7², 7³ and 7⁴ are 7, 9, 3 and 1. Then the cycle repeats.
  2. 2,026 = 4 × 506 + 2, so 7²⁰²⁶ ends like 7².
  3. The last digit is 9.

Answer: 9

Example 3

Solve 5x ≡ 3 (mod 11).

  1. 9 is the inverse of 5 mod 11, because 5 × 9 = 45 = 4 × 11 + 1
  2. Multiply both sides by 9. x ≡ 27 ≡ 5 (mod 11)
  3. Check. 5 × 5 = 25 = 2 × 11 + 3 ✓

Answer: x ≡ 5 (mod 11)

Example 4

Find 100 mod 7.

  1. Find the largest multiple of 7 not above 100. 7 × 14 = 98
  2. The remainder is what is left. 100 − 98 = 2

Answer: 2

Example 5

Use the Euclidean algorithm to find gcd(120, 84).

  1. 120 = 1 × 84 + 36
  2. 84 = 2 × 36 + 12
  3. 36 = 3 × 12 + 0, so the gcd is 12.

Answer: 12