Mathematics · Advanced · 30 min · Chapter 14 of 28
Number theory
The integers, studied for their own structure: divisibility, congruences, and the first theorems about primes.
Read first: Arithmetic and number sense, The language of proof
The idea
Number theory starts from divisibility. We write m | a when a = m q for some integer q. The relation a ≡ b (mod m) means m | (a − b). It splits the integers into m residue classes, and both addition and multiplication descend to those classes. That is modular arithmetic: clocks are arithmetic modulo 12, and bit operations often live modulo 2.
Euclid’s lemma says that if a prime p divides ab, then p divides a or p divides b. Combined with existence of factorizations, it yields uniqueness: the fundamental theorem, already used in arithmetic, is really this lemma. The same circle of ideas produces the fact that there are infinitely many primes. Euclid’s proof still works: if p₁, …, pₖ were all of them, then N = p₁⋯pₖ + 1 would be divisible by none of them, so it would have a new prime factor.
Fermat’s little theorem: if p is prime and p does not divide a, then a^{p−1} ≡ 1 (mod p). Equivalently aᵖ ≡ a (mod p) for every integer a. The generalization is Euler’s theorem, a^{φ(n)} ≡ 1 (mod n) when a and n are coprime, where φ(n) counts integers from 1 to n that are coprime to n. These are the arithmetic engine inside the RSA cryptosystem, which is number theory that happens to encrypt.
Hold onto this
- Congruence a ≡ b (mod m) means m divides a − b. It is an equivalence relation compatible with addition and multiplication.
- If a prime divides a product, it divides one of the factors.
- Fermat’s little theorem constrains powers modulo a prime.
- The integers modulo a prime form a field: every nonzero residue has a multiplicative inverse.
Formulas
Congruence
a and b leave the same remainder when divided by m.
- m
- The modulus, a positive integer
Fermat’s little theorem
When p is prime and p does not divide a. Powers repeat quickly modulo a prime.
- p
- A prime
- a
- An integer not divisible by p
Euler’s theorem
When gcd(a, n) = 1. Fermat is the special case n = p, where φ(p) = p − 1.
- φ(n)
- Euler’s totient
Modular inverse
Has a solution x exactly when gcd(a, m) = 1. Then x is the inverse of a modulo m.
- x
- An integer class modulo m
Worked examples
1. A remainder without a huge power
Find 2¹⁰ (mod 11).
- 11 is prime and does not divide 2, so Fermat says 2¹⁰ ≡ 1 (mod 11).
- Directly: 2⁵ = 32 ≡ −1, so 2¹⁰ ≡ 1. Same answer.
1. The last digits of the division by 11 leave remainder 1.
2. An inverse
Find the inverse of 3 modulo 10.
- gcd(3, 10) = 1, so an inverse exists.
- Try: 3 × 7 = 21 ≡ 1 (mod 10).
7. Check: 3 × 7 = 21, which is one more than a multiple of 10.
Try these
Compute 7⁴ (mod 5) using Fermat.
Does 4 have an inverse modulo 6?
Common mistakes
- Fermat requires a prime modulus and a base not divisible by that prime. Composite moduli need Euler, and only when the base is coprime to the modulus.
- a ≡ b (mod m) does not mean a = b. It means they differ by a multiple of m.
- Cancellation modulo m is legal only when you divide by a unit, i.e., a number coprime to m.