learn › Number Theory

Congruences

lesson · about 3 minutes

Modular inverses, the Chinese remainder theorem, and Fermat.

Pen and paper is fine · no calculator needed why?

Opens at level 44. You're level 1. You can read and practice here now.

the idea

A congruence like x ≡ 3 (mod 5) says x leaves remainder 3 when divided by 5.

The inverse of a mod m is the whole number x with ax ≡ 1 (mod m). Euler's totient φ(n) counts the numbers from 1 to n that share no factor with n except 1. Fermat's little theorem gives a shortcut for big powers divided by a prime.

techniques

List and test

Inverses, and two remainder conditions at once.

  1. Inverse of a mod m: list m + 1, 2m + 1, 3m + 1 and so on.
  2. The first one that a divides, divided by a, is the inverse. For 3 mod 11: 12 ÷ 3 = 4.
  3. Two conditions: list the numbers that fit the larger modulus. Stop at the first that fits the other.
worked example

Example: What is the smallest positive whole number x with x ≡ 2 (mod 3) and x ≡ 4 (mod 7)?

  1. Numbers leaving 4 when divided by 7: 4, 11, 18.
  2. 4 leaves 1 when divided by 3, and 11 leaves 2.
  3. So x is 11.

Answer: 11

Totient from the primes

Working out φ(n).

  1. Find the different primes that divide n.
  2. Multiply n by (1 − 1/p) for each of those primes p.
  3. If n is prime, the answer is n − 1.
worked example

Example: What is φ(40), the count of whole numbers from 1 to 40 that share no factor with 40 other than 1?

  1. 40 is 2³ × 5, so the primes are 2 and 5.
  2. 40 × 1/2 × 4/5 = 16.

Answer: 16

Fermat: shrink the exponent

A power divided by a prime p that does not divide the base.

  1. a to the power p − 1 leaves remainder 1, so every p − 1 in the exponent drops out.
  2. Divide the exponent by p − 1 and keep the remainder r.
  3. Work out a to the power r, and take its remainder by p.
worked example

Example: What is 5⁶² mod 7? Give the remainder from 0 to 6.

  1. 7 is prime, so 5⁶ leaves remainder 1.
  2. 62 = 10 × 6 + 2, so 5⁶² leaves what 5² leaves.
  3. 25 = 3 × 7 + 4, so the answer is 4.

Answer: 4

watch out for

practice

Sign in to try one

Modular inverse

worked example

What is the inverse of 7 modulo 31? Give the whole number x from 1 to 30 with 7x ≡ 1 (mod 31).

Answer: 9

  1. Numbers 1 more than a multiple of 31: 32, 63. The first that divides by 7 is 63.
  2. 63 = 7 × 9, so 7 × 9 ≡ 1 (mod 31) and x = 9.

Euler’s totient

worked example

What is φ(77)? φ(n) counts the whole numbers from 1 to n that share no factor with n other than 1.

Answer: 60

  1. 77 = 7 × 11.
  2. φ(77) = 77 × (1 − 1/7) × (1 − 1/11) = 77 × 6/7 × 10/11 = 60.

Two remainders at once

worked example

What is the smallest positive whole number x with x ≡ 2 (mod 5) and x ≡ 2 (mod 3)?

Answer: 2

  1. List the numbers that leave 2 when divided by 5: 2.
  2. The first of them that leaves 2 when divided by 3 is 2 (2 = 0 × 3 + 2).
  3. So x = 2.

Fermat’s little theorem

worked example

What is 6²³⁶ mod 7? Give the remainder from 0 to 6.

Answer: 1

  1. Fermat: 7 is prime and doesn't divide 6, so 6⁶ ≡ 1 (mod 7).
  2. 236 = 39 × 6 + 2, so 6²³⁶ ≡ 6² (mod 7).
  3. Powers of 6 leave 6, 1 when divided by 7, so 6² ≡ 1.

Sign in to start