SECTION 1
Historical Context & Motivation
The study of prime numbers is among the oldest pursuits in mathematics, stretching back more than two millennia to the ancient Greeks who first recognized that certain integers resist decomposition into smaller factors. The question that animated early number theorists — which numbers are truly indivisible, and how do they compose every other integer? — remains central to modern discrete mathematics and forms the computational backbone of public-key cryptography. Understanding why primes are easy to multiply together yet extraordinarily difficult to recover from their product is the asymmetry upon which protocols like RSA depend.
~300 BCE • Euclid's Elements
~240 BCE • Sieve of Eratosthenes
1801 • Gauss's Disquisitiones Arithmeticae
1977 • RSA Cryptosystem
2002–present • AKS and Post-Quantum Research
The central question that links ancient Greek curiosity to twenty-first-century cybersecurity is deceptively simple: given a large integer n, can we efficiently determine whether it is prime, and if not, can we recover its prime factors? The gap between answering the first question (polynomial time) and the second (no known classical polynomial-time algorithm for general composites) is precisely the asymmetry that modern cryptographic systems exploit.
SECTION 2
Core Principles & Definitions
Before exploring algorithms and applications, we must establish the foundational definitions and theorems that govern the arithmetic of primes. These principles form the axiomatic scaffolding for everything from elementary divisibility arguments to sophisticated cryptographic protocols. A clear grasp of divisibility, primality, and unique factorization is essential for the rigorous reasoning that discrete mathematics demands.
Prime & Composite
Fundamental Theorem of Arithmetic
Divisibility & the Division Algorithm
GCD & Euclid's Algorithm
Infinitude of Primes
KEY TAKEAWAY
SECTION 3
Visualizing the Sieve of Eratosthenes
The Sieve of Eratosthenes provides both an intuitive visualization of how primes are identified and a concrete algorithm with well-understood time complexity. The procedure begins with all integers from 2 to some bound n marked as potentially prime. Starting with the smallest unmarked number (2), the algorithm eliminates all of its proper multiples, then advances to the next surviving number, repeating until it has processed every integer up to √n. The diagram below illustrates this process for integers 2 through 50.
Observe that once the multiples of 2 are eliminated, roughly half the candidates vanish; crossing out multiples of 3 removes another significant fraction, and so on. The key efficiency insight is that the sieve only needs to process primes up to √n, because any composite number m ≤ n must have a prime factor no larger than √m ≤ √n. The sieve's time complexity is O(n log log n), making it remarkably efficient for generating all primes up to moderate bounds and providing a powerful intuition pump for understanding how primes thin out among the integers.
SECTION 4
Mathematical Framework
The theoretical apparatus surrounding primes and factorization rests on several interlocking results. We formalize the key statements and connect them to algorithmic complexity — the bridge between pure number theory and its cryptographic applications.
FUNDAMENTAL THEOREM OF ARITHMETIC
Every integer n > 1 has a unique representation as a product of prime powers, where p₁ < p₂ < … < pₖ are distinct primes and each exponent aᵢ ≥ 1. This factorization is unique up to ordering.
EULER'S TOTIENT FUNCTION
φ(n) counts the integers in {1, …, n} that are coprime to n. For n = p₁^{a₁}…pₖ^{aₖ}, this product formula follows directly from the inclusion-exclusion principle applied to the prime divisors of n. Euler's totient is central to RSA key generation.
PRIME NUMBER THEOREM
π(x) denotes the number of primes not exceeding x. The theorem states that the ratio π(x) / (x / ln x) approaches 1, meaning primes become sparser logarithmically. This informs the expected size of a random prime near a given magnitude and directly influences the key-size estimates used in cryptographic standards.
TRIAL DIVISION COMPLEXITY
The simplest primality test divides n by every integer from 2 to ⌊√n⌋. If no divisor is found, n is prime. While straightforward, this is exponential in the number of digits of n (bit-length b implies √n = ), which is why it is impractical for cryptographic-scale numbers with hundreds of digits.
Bit-Length vs. Magnitude
SECTION 5
Factorization Algorithms & Classification
Factorization algorithms range from elementary procedures suitable for small integers to sophisticated sub-exponential methods designed for cryptographic-scale numbers. The classification below distinguishes algorithms by their asymptotic complexity and practical applicability. Understanding this landscape clarifies both why factorization is considered hard and where the boundaries of current computational capability lie.
| Algorithm | Complexity Class | Best For | Practical Limit |
|---|---|---|---|
| Trial Division | Exponential: O() | Small factors, pedagogical clarity | ~20 digits |
| Pollard's ρ | O() expected | Finding small-to-medium prime factors | ~30 digits |
| Quadratic Sieve | Sub-exponential: [1/2, 1] | Integers up to ~100 digits | ~100 digits |
| GNFS | Sub-exponential: [1/3, c] | Largest known factorizations | ~250 digits (current record) |
| Shor's Algorithm | Polynomial: O(b³) | Quantum computers (theoretical) | Limited by qubit count |
Summary of major factorization algorithms
The notation [α, c] = exp(c × (ln n)^α × ) provides a unified way to express sub-exponential complexity. When α = 0 we recover polynomial time, and when α = 1 we recover fully exponential time; the factorization algorithms of greatest practical interest sit at α = 1/3 (GNFS) or α = 1/2 (Quadratic Sieve), occupying the critical middle ground that makes factorization hard but not impossibly so — exactly the sweet spot that RSA exploits by choosing key sizes that push n beyond the reach of the fastest known classical algorithms.
SECTION 6
Worked Example: Prime Factorization & Euler's Totient
We now walk through a complete factorization of a composite number and compute Euler's totient function — the precise calculation that appears during RSA key generation. The goal is to connect the theoretical framework to a concrete computation.
Factor n = 2520 and compute φ(2520)
- 1
Step 1 — Begin with the smallest prime
Divide 2520 by 2 repeatedly: 2520 ÷ 2 = 1260, 1260 ÷ 2 = 630, 630 ÷ 2 = 315. Since 315 is odd, we have extracted the full power of 2.2520 = 2³ × 315 - 2
Step 2 — Continue with the next prime (3)
Divide 315 by 3: 315 ÷ 3 = 105, 105 ÷ 3 = 35. Since 35 is not divisible by 3, we stop.2520 = 2³ × 3² × 35 - 3
Step 3 — Continue with 5
Divide 35 by 5: 35 ÷ 5 = 7. Since 7 is not divisible by 5, we extract a single factor of 5.2520 = 2³ × 3² × 5¹ × 7 - 4
Step 4 — Check if the remaining factor is prime
The remaining factor is 7. Since 7 is prime (√7 ≈ 2.65, and 7 is not divisible by 2), the factorization is complete.2520 = 2³ × 3² × 5 × 7 - 5
Step 5 — Compute φ(2520)
Apply the totient product formula: φ(2520) = 2520 × (1 − 1/2) × (1 − 1/3) × (1 − 1/5) × (1 − 1/7) = 2520 × (1/2) × (2/3) × (4/5) × (6/7). Computing step by step: 2520 × 1/2 = 1260; 1260 × 2/3 = 840; 840 × 4/5 = 672; 672 × 6/7 = 576.φ(2520) = 576 - 6
Step 6 — Interpret the result
Of the 2520 integers from 1 to 2520, exactly 576 are coprime to 2520. In an RSA context, if n = p × q with p and q prime, then φ(n) = (p − 1)(q − 1), and the private key exponent d is chosen such that e × d ≡ 1 (mod φ(n)). The ability to compute φ(n) hinges on knowing the factorization of n — this is precisely the trapdoor.576 / 2520 ≈ 22.9% of integers ≤ 2520 are coprime to it
SECTION 7
Primality Testing: Methods Compared
While factorization remains computationally difficult for large numbers, primality testing — merely determining whether a number is prime without finding its factors — can be done efficiently. This asymmetry is essential: RSA key generation requires finding large primes quickly, even though verifying that their product is hard to factor. The table below compares the major primality tests along several dimensions relevant to both theory and implementation.
| Method | Type | Complexity | Limitations |
|---|---|---|---|
| Trial Division | Deterministic | O(√n) — exponential in bit-length | Impractical beyond ~20 digits |
| Fermat Test | Probabilistic | O(k × b² log b) | Fooled by Carmichael numbers (pseudoprimes to all bases) |
| Miller–Rabin | Probabilistic (Monte Carlo) | O(k × b² log b); error ≤ | Non-zero (but tunable) error probability |
| AKS | Deterministic | Õ() — polynomial | Theoretically polynomial but slower in practice than Miller–Rabin |
Primality testing methods comparison
KEY TAKEAWAY
SECTION 8
Connection to Cryptography & Advanced Theory
The theoretical hardness of integer factorization translates directly into the security guarantees of the RSA cryptosystem, which remains one of the most widely deployed public-key algorithms. In RSA, a user selects two large primes p and q, publishes n = pq, and keeps the factorization secret. The public key consists of (n, e) and the private key of d, where ed ≡ 1 (mod φ(n)). An adversary who can factor n can compute φ(n) = (p − 1)(q − 1) and thereby recover d; conversely, without the factorization, computing d from (n, e) is believed to be computationally infeasible.
| Concept | Elementary Number Theory | Cryptographic Application |
|---|---|---|
| Prime factorization | Unique decomposition of integers (FTA) | Hardness of factoring n = pq is the RSA security assumption |
| Euler's totient | Counting coprime residues mod n | φ(n) = (p−1)(q−1) determines the RSA private exponent d |
| Modular exponentiation | Euler's theorem: ≡ 1 (mod n) for gcd(a,n)=1 | Encryption: c ≡ (mod n); Decryption: m ≡ (mod n) |
| Primality testing | Determining if n is prime (polynomial time) | Efficient generation of large primes for key pairs |
| Discrete logarithm | Finding x such that ≡ h (mod p) | Basis for Diffie–Hellman key exchange and ElGamal encryption |
From number theory to cryptographic protocols
Looking forward, the advent of scalable quantum computing poses a fundamental challenge to factorization-based cryptography. Shor's algorithm factors integers in polynomial time on a quantum computer, rendering RSA insecure once sufficiently large quantum machines exist. This has spurred the development of post-quantum cryptography, including lattice-based schemes (e.g., NTRU, Kyber) and code-based systems whose security rests on problems believed to be hard even for quantum computers. The study of primes and factorization thus remains not merely historically significant but actively evolving, as the mathematical community works to understand which computational assumptions will survive the quantum era.
SECTION 9
Practice Problems
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Lesson Summary
Summary
This lesson established that prime numbers are the multiplicative building blocks of the integers, formalized by the Fundamental Theorem of Arithmetic, which guarantees unique factorization of every integer greater than 1. We traced the subject from Euclid's ancient proof of infinitude through the Sieve of Eratosthenes to the Prime Number Theorem, which describes the asymptotic density of primes. Key tools include Euler's totient function φ(n), the Euclidean algorithm for computing greatest common divisors, and Euclid's Lemma, which underpins the uniqueness proof of the FTA.
On the computational side, we distinguished between primality testing (efficiently solvable via Miller–Rabin or deterministic AKS) and integer factorization (for which no classical polynomial-time algorithm is known). This asymmetry is the foundation of the RSA cryptosystem, where multiplying two large primes is trivial but recovering them from the product is computationally intractable. The emerging threat of Shor's quantum algorithm underscores the need for post-quantum cryptographic alternatives, ensuring that the interplay between prime number theory and information security will remain a vibrant area of research for decades to come.