Often called the "Queen of Mathematics," number theory is the study of the integers and their remarkable properties. From ancient questions about prime numbers to modern cryptographic systems that secure the internet, number theory connects deep abstraction with powerful real-world applications.
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. Its origins stretch back to antiquity — the ancient Greeks, especially Euclid and Diophantus, investigated properties of numbers that continue to fascinate mathematicians today.
Carl Friedrich Gauss famously remarked, "Mathematics is the queen of the sciences, and number theory is the queen of mathematics." For centuries number theory was considered the purest of pure mathematics — beautiful but seemingly impractical. That changed dramatically in the late 20th century when number-theoretic ideas became the backbone of modern cryptography and computer security.
Number theory asks deceptively simple questions: Which numbers are prime? How are the primes distributed among the integers? Can every even number greater than 2 be written as the sum of two primes? These questions are easy to state, yet many remain unsolved to this day.
Number theory begins with the most fundamental objects in mathematics: the natural numbers ℕ = {1, 2, 3, 4, …} (some authors include 0) and the integers ℤ = {…, -3, -2, -1, 0, 1, 2, 3, …}.
In the late 19th century, Giuseppe Peano formalized the natural numbers with a set of axioms that capture their essential structure:
Mathematical induction is the proof technique derived directly from the Peano axioms. To prove a statement P(n) for all natural numbers n ≥ 1:
Base case (n = 1): Left side = 1. Right side = 1(2)/2 = 1. ✓
Inductive step: Assume 1 + 2 + … + k = k(k + 1)/2.
Then 1 + 2 + … + k + (k + 1) = k(k + 1)/2 + (k + 1)
= (k + 1)[k/2 + 1] = (k + 1)(k + 2)/2
This is exactly the formula with n = k + 1. ✓
By induction, the formula holds for all n ≥ 1.
The Well-Ordering Principle states that every non-empty subset of the natural numbers has a least element. Although this sounds obvious, it is logically equivalent to the Principle of Mathematical Induction and is a powerful proof tool.
Many fundamental results in number theory — including the existence of prime factorizations — rely on well-ordering. The typical proof strategy is proof by contradiction: assume a counterexample exists, then use well-ordering to find a minimal counterexample, and derive a contradiction.
Claim: Every integer n ≥ 2 has a prime factor.
Proof: Suppose for contradiction that there exists an integer n ≥ 2 with no prime factor. By well-ordering, there is a smallest such integer, call it m.
Since m has no prime factor, m is not itself prime (otherwise m would be its own prime factor). So m is composite: m = a · b where 2 ≤ a, b < m.
Since a < m and a ≥ 2, the minimality of m implies a has a prime factor p. But then p also divides m — contradiction.
Therefore every integer n ≥ 2 has a prime factor. ✓
Divisibility is the most basic concept in number theory. We say that an integer a divides an integer b if there exists an integer k such that b = a · k. We write a | b (read "a divides b").
For integers a, b, c:
Claim: If a | b and b | c, then a | c.
Proof: Since a | b, we have b = a · k₁ for some integer k₁.
Since b | c, we have c = b · k₂ for some integer k₂.
Substituting: c = (a · k₁) · k₂ = a · (k₁ · k₂).
Since k₁ · k₂ is an integer, a | c. ✓
The Division Algorithm is a cornerstone of number theory. Despite its name, it is a theorem, not an algorithm.
Divide 47 by 5:
47 = 5 · 9 + 2, so q = 9 and r = 2.
Divide -23 by 7:
-23 = 7 · (-4) + 5, so q = -4 and r = 5.
(Note: the remainder is always non-negative, so we need 7 · (-4) = -28, and -23 - (-28) = 5.)
Quick tests to determine whether a number is divisible by small primes:
By 2: Last digit is 4 (even) → Yes ✓
By 3: 2 + 5 + 7 + 4 = 18, and 18 ÷ 3 = 6 → Yes ✓
By 9: Digit sum = 18, and 18 ÷ 9 = 2 → Yes ✓
By 11: 2 - 5 + 7 - 4 = 0, and 0 is divisible by 11 → Yes ✓
So 2,574 is divisible by 2, 3, 6, 9, and 11.
A prime number is an integer greater than 1 whose only positive divisors are 1 and itself. An integer greater than 1 that is not prime is called composite.
The first few primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, …
One of the most elegant proofs in all of mathematics, dating back over 2,300 years:
Proof (Euclid): Suppose, for contradiction, that there are only finitely many primes: p₁, p₂, …, pₙ.
Consider the number N = p₁ · p₂ · … · pₙ + 1.
N is greater than 1, so it has a prime factor p (by the result proved earlier).
But p cannot be any of p₁, p₂, …, pₙ, because dividing N by any pᵢ leaves remainder 1.
This contradicts our assumption that p₁, …, pₙ are all the primes. ✓
Therefore, there are infinitely many primes.
This theorem establishes that primes are the "building blocks" of all integers:
The existence part is proved by strong induction; the uniqueness part uses a key property of primes called Euclid's Lemma: if a prime p divides a product ab, then p | a or p | b.
360 = 2³ · 3² · 5
1,001 = 7 · 11 · 13
2,310 = 2 · 3 · 5 · 7 · 11
10,000 = 2⁴ · 5⁴
Each factorization is unique (aside from rearranging the order).
The Sieve of Eratosthenes is an ancient and efficient algorithm for finding all primes up to a given limit N:
Start: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
Sieve by 2: Keep 2; cross out 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
Sieve by 3: Keep 3; cross out 9, 15, 21, 27
Sieve by 5: Keep 5; cross out 25
We stop at √30 ≈ 5.47, so we're done.
Primes up to 30: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29
Although primes become less frequent among larger numbers, they never "run out." The Prime Number Theorem, proved independently by Hadamard and de la Vallée Poussin in 1896, describes their asymptotic distribution:
Here π(x) denotes the number of primes less than or equal to x. Informally, the "probability" that a randomly chosen number near x is prime is approximately 1/ln(x).
Twin primes are pairs of primes that differ by exactly 2. Examples include (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), and (71, 73).
The Twin Prime Conjecture asserts that there are infinitely many twin prime pairs. Despite intensive effort, this remains unproven. In 2013, Yitang Zhang made a breakthrough by proving that there are infinitely many pairs of primes differing by at most 70 million — a bound later reduced to 246 by the Polymath project.
The greatest common divisor (GCD) of two integers a and b (not both zero) is the largest positive integer that divides both a and b. We write gcd(a, b).
The least common multiple (LCM) of two positive integers a and b is the smallest positive integer that is divisible by both a and b. We write lcm(a, b).
If a = p₁^α₁ · p₂^α₂ · … · pₖ^αₖ and b = p₁^β₁ · p₂^β₂ · … · pₖ^βₖ (using all primes from both factorizations, with zero exponents where needed), then:
360 = 2³ · 3² · 5¹ · 7⁰
756 = 2² · 3³ · 5⁰ · 7¹
gcd(360, 756) = 2^min(3,2) · 3^min(2,3) · 5^min(1,0) · 7^min(0,1) = 2² · 3² · 1 · 1 = 4 · 9 = 36
lcm(360, 756) = 2^max(3,2) · 3^max(2,3) · 5^max(1,0) · 7^max(0,1) = 2³ · 3³ · 5 · 7 = 8 · 27 · 5 · 7 = 7,560
This elegant relationship connects the GCD and LCM. Using the example above: 36 · 7,560 = 272,160 = 360 · 756. ✓
The Euclidean Algorithm is one of the oldest and most important algorithms in mathematics (dating to ~300 BCE). It computes gcd(a, b) efficiently without needing prime factorizations, using the key property:
Repeatedly apply this until the remainder is 0. The last nonzero remainder is the GCD.
252 = 198 · 1 + 54 → gcd(252, 198) = gcd(198, 54)
198 = 54 · 3 + 36 → gcd(198, 54) = gcd(54, 36)
54 = 36 · 1 + 18 → gcd(54, 36) = gcd(36, 18)
36 = 18 · 2 + 0 → Done!
gcd(252, 198) = 18
The Extended Euclidean Algorithm not only computes gcd(a, b) but also finds integers x and y such that:
This is crucial for solving linear congruences and in the RSA cryptosystem.
From our work above, we back-substitute:
18 = 54 - 36 · 1
18 = 54 - (198 - 54 · 3) · 1 = 54 · 4 - 198 · 1
18 = (252 - 198 · 1) · 4 - 198 · 1 = 252 · 4 - 198 · 5
So 252 · 4 + 198 · (-5) = 18, giving x = 4, y = -5.
Check: 252 · 4 = 1,008 and 198 · 5 = 990; 1,008 - 990 = 18. ✓
Modular arithmetic is the arithmetic of remainders. Introduced systematically by Gauss in Disquisitiones Arithmeticae (1801), it is one of the most powerful concepts in number theory and has vast applications in computer science, cryptography, and pure mathematics.
We say that a is congruent to b modulo m (written a ≡ b (mod m)) if m divides the difference a - b:
17 ≡ 2 (mod 5) because 17 - 2 = 15, and 5 | 15. ✓
-3 ≡ 4 (mod 7) because -3 - 4 = -7, and 7 | (-7). ✓
100 ≡ 0 (mod 4) because 100 - 0 = 100, and 4 | 100. ✓
38 ≡ 14 (mod 12) because 38 - 14 = 24, and 12 | 24. ✓
Congruence modulo m is an equivalence relation (reflexive, symmetric, transitive) and is compatible with addition and multiplication:
Find 3¹⁰⁰ mod 7:
3¹ ≡ 3 (mod 7)
3² ≡ 9 ≡ 2 (mod 7)
3³ ≡ 6 ≡ -1 (mod 7)
3⁶ ≡ (-1)² ≡ 1 (mod 7)
Since 100 = 6 · 16 + 4:
3¹⁰⁰ = (3⁶)¹⁶ · 3⁴ ≡ 1¹⁶ · 3⁴ ≡ 81 ≡ 4 (mod 7)
3¹⁰⁰ ≡ 4 (mod 7)
The integers modulo m fall into m distinct residue classes: {0, 1, 2, …, m - 1}. This set, denoted ℤ/mℤ (or ℤₘ), forms a ring under addition and multiplication modulo m.
An integer a has a multiplicative inverse modulo m — an integer a⁻¹ such that a · a⁻¹ ≡ 1 (mod m) — if and only if gcd(a, m) = 1. We find it using the Extended Euclidean Algorithm.
We need x such that 7x ≡ 1 (mod 11).
Using the Extended Euclidean Algorithm:
11 = 7 · 1 + 4
7 = 4 · 1 + 3
4 = 3 · 1 + 1
Back-substitute: 1 = 4 - 3 = 4 - (7 - 4) = 2 · 4 - 7 = 2(11 - 7) - 7 = 2 · 11 - 3 · 7
So 7 · (-3) ≡ 1 (mod 11), meaning 7⁻¹ ≡ -3 ≡ 8 (mod 11).
Check: 7 · 8 = 56 = 5 · 11 + 1, so 56 ≡ 1 (mod 11). ✓
A linear congruence ax ≡ b (mod m) has a solution if and only if gcd(a, m) | b. If d = gcd(a, m) divides b, there are exactly d incongruent solutions modulo m.
d = gcd(6, 21) = 3. Since 3 | 15, solutions exist (and there will be 3 of them).
Divide through by 3: 2x ≡ 5 (mod 7).
Find 2⁻¹ mod 7: 2 · 4 = 8 ≡ 1 (mod 7), so 2⁻¹ ≡ 4 (mod 7).
Multiply both sides by 4: x ≡ 20 ≡ 6 (mod 7).
The 3 solutions modulo 21 are: x ≡ 6, 13, 20 (mod 21).
Check: 6 · 6 = 36 ≡ 15 (mod 21) ✓; 6 · 13 = 78 ≡ 15 (mod 21) ✓; 6 · 20 = 120 ≡ 15 (mod 21) ✓
One of the most important results in number theory, stated by Pierre de Fermat in 1640:
An equivalent formulation that works for all integers a (including multiples of p):
Let a = 3, p = 7:
3⁶ = 729. Now 729 ÷ 7 = 104 remainder 1.
So 3⁶ ≡ 1 (mod 7). ✓
Let a = 2, p = 13:
2¹² = 4,096. Now 4,096 ÷ 13 = 315 remainder 1.
So 2¹² ≡ 1 (mod 13). ✓
Find 2³⁴⁰ mod 11:
Since 11 is prime and gcd(2, 11) = 1, Fermat says 2¹⁰ ≡ 1 (mod 11).
340 = 10 · 34, so 2³⁴⁰ = (2¹⁰)³⁴ ≡ 1³⁴ ≡ 1 (mod 11).
Euler's totient function φ(n) counts the number of integers from 1 to n that are coprime to n:
φ(12): 12 = 2² · 3. So φ(12) = 12 · (1 - 1/2) · (1 - 1/3) = 12 · 1/2 · 2/3 = 4.
Check: integers coprime to 12 in {1, …, 12} are {1, 5, 7, 11} — indeed 4 elements. ✓
φ(36): 36 = 2² · 3². So φ(36) = 36 · (1 - 1/2) · (1 - 1/3) = 36 · 1/2 · 2/3 = 12.
φ(100): 100 = 2² · 5². So φ(100) = 100 · (1 - 1/2) · (1 - 1/5) = 100 · 1/2 · 4/5 = 40.
Euler's Theorem generalizes Fermat's Little Theorem from primes to all positive integers:
When n = p is prime, φ(p) = p - 1, so this reduces to Fermat's Little Theorem.
Find 7¹⁰⁰ mod 12:
gcd(7, 12) = 1 ✓. φ(12) = 4 (computed above).
By Euler's Theorem: 7⁴ ≡ 1 (mod 12).
100 = 4 · 25, so 7¹⁰⁰ = (7⁴)²⁵ ≡ 1²⁵ ≡ 1 (mod 12).
The Chinese Remainder Theorem (CRT) is a result about simultaneous congruences that dates back to the 3rd century Chinese mathematician Sun Tzu (Sunzi). It says that a system of congruences with pairwise coprime moduli has a unique solution.
To find the solution explicitly:
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7)
Step 1: M = 3 · 5 · 7 = 105.
Step 2: M₁ = 105/3 = 35, M₂ = 105/5 = 21, M₃ = 105/7 = 15.
Step 3: Find inverses:
35y₁ ≡ 1 (mod 3): 35 ≡ 2 (mod 3), 2 · 2 = 4 ≡ 1 (mod 3), so y₁ = 2.
21y₂ ≡ 1 (mod 5): 21 ≡ 1 (mod 5), so y₂ = 1.
15y₃ ≡ 1 (mod 7): 15 ≡ 1 (mod 7), so y₃ = 1.
Step 4: x ≡ 2 · 35 · 2 + 3 · 21 · 1 + 2 · 15 · 1 = 140 + 63 + 30 = 233 ≡ 233 - 2 · 105 = 23 (mod 105).
Solution: x ≡ 23 (mod 105)
Check: 23 = 3 · 7 + 2, so 23 ≡ 2 (mod 3) ✓; 23 = 5 · 4 + 3, so 23 ≡ 3 (mod 5) ✓; 23 = 7 · 3 + 2, so 23 ≡ 2 (mod 7) ✓
Solve: x ≡ 3 (mod 8) and x ≡ 5 (mod 13).
From the first: x = 8k + 3 for some integer k.
Substitute into the second: 8k + 3 ≡ 5 (mod 13), so 8k ≡ 2 (mod 13).
Find 8⁻¹ mod 13: 8 · 5 = 40 ≡ 1 (mod 13), so 8⁻¹ ≡ 5.
k ≡ 2 · 5 ≡ 10 (mod 13).
x = 8 · 10 + 3 = 83.
Solution: x ≡ 83 (mod 104)
Check: 83 = 8 · 10 + 3 ✓; 83 = 13 · 6 + 5 ✓
Diophantine equations are polynomial equations where we seek integer solutions. They are named after Diophantus of Alexandria (c. 200–284 CE), who studied them extensively. Unlike ordinary algebra — where solutions can be any real or complex number — Diophantine equations restrict solutions to integers, making them much harder to analyze.
The simplest type is the linear Diophantine equation in two variables:
Existence of solutions: The equation ax + by = c has integer solutions if and only if gcd(a, b) | c.
Finding all solutions: If (x₀, y₀) is one particular solution, then all solutions are:
Step 1: Check existence. gcd(15, 21) = 3, and 3 | 12. ✓ Solutions exist.
Step 2: Simplify by dividing by 3: 5x + 7y = 4.
Step 3: Find one particular solution using the Extended Euclidean Algorithm.
gcd(5, 7): 7 = 5 · 1 + 2; 5 = 2 · 2 + 1; so 1 = 5 - 2 · 2 = 5 - 2(7 - 5) = 3 · 5 - 2 · 7.
Therefore 5 · 3 + 7 · (-2) = 1. Multiply by 4: 5 · 12 + 7 · (-8) = 4.
A particular solution is x₀ = 12, y₀ = -8.
Step 4: General solution: x = 12 + 7t, y = -8 - 5t for any integer t.
Check (t = 0): 15(12) + 21(-8) = 180 - 168 = 12. ✓
Check (t = -1): 15(5) + 21(-3) = 75 - 63 = 12. ✓
Integer solutions are called Pythagorean triples. The complete parametric solution for primitive Pythagorean triples (where gcd(x, y, z) = 1) is:
where m > n > 0, gcd(m, n) = 1, and m - n is odd.
m = 2, n = 1: x = 4 - 1 = 3, y = 4, z = 4 + 1 = 5 → (3, 4, 5)
m = 3, n = 2: x = 9 - 4 = 5, y = 12, z = 9 + 4 = 13 → (5, 12, 13)
m = 4, n = 1: x = 16 - 1 = 15, y = 8, z = 16 + 1 = 17 → (8, 15, 17)
m = 4, n = 3: x = 16 - 9 = 7, y = 24, z = 16 + 9 = 25 → (7, 24, 25)
Pierre de Fermat conjectured in 1637 that the equation xⁿ + yⁿ = zⁿ has no positive integer solutions for n ≥ 3. He famously wrote that he had "a truly marvelous proof that this margin is too narrow to contain."
This conjecture stood unsolved for 358 years until Andrew Wiles proved it in 1995, in one of the greatest mathematical achievements of the 20th century. The proof uses deep ideas from algebraic geometry and modular forms, far beyond elementary number theory.
For a positive non-square integer D, Pell's equation always has infinitely many solutions. The fundamental solution can be found using continued fractions.
We seek integer solutions. Trying small values:
y = 0: x² = 1, so x = 1. Solution: (1, 0).
y = 1: x² = 3, no integer solution.
y = 2: x² = 9, so x = 3. Solution: (3, 2). ✓
From the fundamental solution (3, 2), all solutions can be generated via:
(xₙ₊₁, yₙ₊₁) = (3xₙ + 4yₙ, 2xₙ + 3yₙ)
Next solution: x = 3·3 + 4·2 = 17, y = 2·3 + 3·2 = 12. Check: 17² - 2·12² = 289 - 288 = 1. ✓
Next: x = 3·17 + 4·12 = 99, y = 2·17 + 3·12 = 70. Check: 99² - 2·70² = 9801 - 9800 = 1. ✓
Modern cryptography relies heavily on number theory. The security of many encryption systems depends on the computational difficulty of certain number-theoretic problems — particularly integer factorization and the discrete logarithm problem.
A one-way function is easy to compute in one direction but computationally infeasible to reverse. Number theory provides natural one-way functions:
The RSA algorithm, invented by Rivest, Shamir, and Adleman in 1977, is one of the first and most widely used public-key cryptosystems. It rests entirely on results from number theory: Euler's Theorem, modular inverses, and the difficulty of factoring large numbers.
where M is the plaintext message (as a number less than n) and C is the ciphertext.
By construction, e · d ≡ 1 (mod φ(n)), so e · d = 1 + k · φ(n) for some integer k. Then:
The crucial step uses Euler's Theorem: M^φ(n) ≡ 1 (mod n) when gcd(M, n) = 1.
Key Generation:
Choose p = 61, q = 53.
n = 61 · 53 = 3,233.
φ(n) = (61 - 1)(53 - 1) = 60 · 52 = 3,120.
Choose e = 17 (gcd(17, 3120) = 1 ✓).
Find d: 17d ≡ 1 (mod 3120). Using the Extended Euclidean Algorithm: d = 2,753.
Check: 17 · 2,753 = 46,801 = 15 · 3,120 + 1, so 17 · 2,753 ≡ 1 (mod 3,120). ✓
Public key: (3233, 17). Private key: (3233, 2753).
Encryption: Encrypt the message M = 65.
C ≡ 65¹⁷ (mod 3233).
Using repeated squaring: 65² = 4,225 ≡ 992 (mod 3233); 65⁴ ≡ 992² = 984,064 ≡ 2,149 (mod 3233); … continuing: C = 2,790.
Decryption: Recover M from C = 2,790.
M ≡ 2,790²⁷⁵³ (mod 3233) = 65. ✓
The original message is recovered!
RSA's security rests on the assumption that factoring n = pq is computationally infeasible when p and q are sufficiently large. If an attacker could factor n, they could compute φ(n) = (p - 1)(q - 1) and then recover the private key d. Current RSA implementations use keys of 2048 bits or more.