courses › Number Theory

Congruences

level 44 course

Modular inverses, the Chinese remainder theorem, and Fermat.

Pen and paper is fine · no calculator needed why?

Learn first (about 3 minutes)

Opens at level 44.

Sign in to start

Builds on: Clock arithmetic (not open yet)

the lesson

The idea, the techniques and a tip for each skill, right here. The Learn page adds worked examples for every skill and untimed practice.

Read the lesson · about 3 minutes

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

Tips by skill

  • TipModular inverse: List the numbers 1 more than a multiple of the modulus. The first one a divides, divided by a, is the inverse.
  • TipEuler’s totient: Find the different primes dividing n. Multiply n by (1 − 1/p) for each one.
  • TipTwo remainders at once: List the numbers that fit the larger modulus. The first that also fits the other condition is the answer.
  • TipFermat’s little theorem: Only the exponent's remainder by p − 1 matters. Then work out that small power and take its remainder.

Watch out for

  • Giving a fraction like 1/3 for an inverse. The inverse is a whole number from 1 to m − 1.
  • Using n − 1 for φ(n) when n is not prime.
  • Stopping at a solution that is not the smallest. Subtract the product of the two moduli.
  • Reducing the exponent by p instead of p − 1 when using Fermat.

skills · practice stats

From rounds of this course only: box, review and test-out answers are left out. Once a skill has 40 tries, it compares your first 20 tries with your last 20.

rest ladder

Win 3 of your last 4 rounds and the course rests. A win is 90% right, within 2× the round's par. Pass the review when it comes back and the next rest is longer.

  1. 1 day
  2. 3 days
  3. 7 days
  4. 14 days
  5. 30 days
  6. 60 days
  7. mastered · every 90 days

your rounds

No rounds yet.