Prime Numbers and Primality Testing
A prime number is an integer greater than 1 whose only positive divisors are 1 and itself. Every integer factors uniquely into primes (the Fundamental Theorem of Arithmetic), making primes the multiplicative atoms of number theory. Primality testing answers "is prime?" — solved efficiently by probabilistic tests (Miller–Rabin) and, since 2002, by a deterministic polynomial-time algorithm (AKS). Primes underpin modern cryptography (RSA, Diffie–Hellman). Studied since Euclid (~300 BCE); deep questions (twin primes, Riemann Hypothesis) remain open today.
Primes are defined by indivisibility but behave like atoms: their power comes from the unique factorization of integers. Two distinct circles of ideas grow from this — (1) the multiplicative theory: how primes combine, distribute, and density (Prime Number Theorem); and (2) the algorithmic question: given , can we decide primality and find factors quickly? Remarkably, deciding whether is prime is computationally easy, while factoring into primes is believed to be hard — an asymmetry that secures the digital world.
Formal Statement
An integer is prime if and its only positive divisors are and . An integer that is not prime is composite: there exist integers with and . The integer is a unit — neither prime nor composite. Divisibility means for some integer .
Derivation hint: This is the definition unpacked with the divisibility relation; the universal quantifier states "no nontrivial divisor exists."
Every integer can be written as a product of primes, and this representation is unique up to the order of the factors.
Derivation hint: Existence follows by strong induction (split any composite into smaller factors); uniqueness follows from Euclid's Lemma below.
If a prime divides a product , then or .
Derivation hint: Since is prime and , the only common divisor of is ; by Bézout , multiply by to get .
There are infinitely many prime numbers.
Derivation hint: leaves remainder when divided by each , so any prime factor of is new — contradicting the assumption of a finite complete list.
Let count primes . Then is asymptotic to .
Derivation hint: Follows from the non-vanishing of the Riemann zeta function on the line ; proven independently by Hadamard and de la Vallée Poussin (1896).
Why It Holds / Derivation
We prove the uniqueness part of Fundamental Theorem of Arithmetic using Euclid's Lemma. 1. Setup. Suppose some integer has two prime factorizations. By well-ordering, let be the smallest such integer:
2. Apply Euclid's Lemma. Since , repeated application of equation shows for some . 3. Match the factors. Because is prime, its only divisors are and ; since , we get . 4. Cancel and descend. Dividing both sides by gives a smaller integer with two factorizations (the 's minus , the 's minus ). By minimality of , these must agree, forcing the original factorizations to agree. 5. Conclusion. No smallest counterexample exists, so factorization is unique up to order.
∎If is prime and , then . 1. Consider the residues . 2. These are a permutation of : if then , and since , we get , so all are distinct and nonzero. 3. Multiply them all together:
4. Since , cancel to obtain . This gives a primality test: if for some coprime to , then is definitely composite.
∎Euclid's Elements, Book IX, contains the earliest surviving proof of the infinitude of primes (Proposition 20) and the foundational results on divisibility that became Euclid's Lemma. His method — assume finiteness, construct a new prime — is a paradigm of proof by contradiction still taught unchanged 2,300 years later. The Elements also gives the Euclidean algorithm for the greatest common divisor, the computational engine behind Bézout's identity and thus behind Euclid's Lemma itself.
Building Intuition
Think of integers as Lego structures and primes as the indivisible bricks. Multiplication snaps bricks together; the Fundamental Theorem says each structure has a unique parts list. Now, why are primes hard to predict? Because primality is a global property — to know is prime you must rule out every potential divisor. Yet there is order in the chaos: primes near appear roughly once every integers (PNT), so around a billion you expect a prime about every 21 numbers. The asymmetry powering cryptography: checking primality only needs a few modular exponentiations (fast), but factoring a 600-digit semiprime would take longer than the age of the universe on classical hardware.
Worked Examples
Given: Determine whether is prime.
Steps: 1. Trial division only needs primes , i.e. test . 2. is odd → not divisible by . 3. Digit sum , not divisible by . 4. Does not end in or → not divisible by . 5. → not divisible by . 6. All primes up to fail, so no nontrivial factor exists.
Answer: (the 25th prime).
Given: Apply the Miller–Rabin test to with witness .
Steps: 1. Write , so , . 2. Compute . By repeated squaring: . 3. Since and , square: . 4. ; . 5. We reached from : this is a nontrivial square root of 1, proving composite. 6. Indeed . Note: the weaker Fermat test gives — it is fooled! Miller–Rabin catches it.
Answer: ; witness exposes it where the Fermat test fails.
Common Misconceptions
"Passing the Fermat test means is prime." False. There exist composite (the Carmichael numbers: ) for which for every coprime to . The Fermat test cannot detect these. Miller–Rabin fixes this by additionally checking nontrivial square roots of . Never rely on a single Fermat test for security-grade primality.
"1 is prime." No — is a unit. If were prime, unique factorization in equation would fail, since . Excluding is a definitional choice that preserves the Fundamental Theorem.
Mersenne numbers are not all prime. A common belief is that is prime whenever is prime. Counterexample: is prime, but
So primality of the exponent is necessary but not sufficient. The largest known primes are Mersenne primes precisely because the Lucas–Lehmer test makes them cheap to verify — not because all such numbers are prime.
Connections
Prime numbers sit at the crossroads of many fields. Modular Arithmetic turns into a field exactly when is prime, the algebraic source of Fermat's Little Theorem. Group Theory explains primality tests: the multiplicative group has order iff is prime, and Lagrange's theorem forces . The Riemann Zeta Function encodes the distribution of primes through its Euler product , linking primality to complex analysis. Computational Complexity frames the deep contrast: primality is in P (AKS), while integer factorization's hardness is the open foundation of Public-Key Cryptography.
Real-World Applications
Historical Development
Subtleties & Limits
Several central questions about primes remain unsolved:
- Riemann Hypothesis: all nontrivial zeros of have real part . This would give the sharpest possible error term in the Prime Number Theorem, .
- Twin Prime Conjecture: infinitely many primes with also prime. Zhang (2013) proved infinitely many prime gaps ; the bound is now (Polymath/Maynard).
- Goldbach's Conjecture: every even integer is a sum of two primes — verified to but unproven.
- Practical factoring vs. quantum computers: Shor's algorithm factors in polynomial time on a quantum computer, threatening RSA — motivating post-quantum cryptography. The exact classical complexity of factoring is unknown (not proven to be NP-hard, not known to be in P).
See Also
Modular Arithmetic · Fundamental Theorem of Arithmetic · Riemann Zeta Function · Public-Key Cryptography · Finite Fields · Euclidean Algorithm · Sieve of Eratosthenes · Group Theory