MathLabs

Arithmetic and number theory

Prime number theorem

Describes how the density of prime numbers thins out, approximately as 1/ln(n), among the integers.

IntuitionHow rare are primes, really?

Among the first ten integers, 44 are prime — a density of 40%40\%. Among the first hundred, only 2525 are prime — 25%25\%. Among the first million, just 78,49878{,}498 are — under 8%8\%. Primes never stop (Euclid proved that around 300 BCE), but they get rarer and rarer the further out you look. The prime number theorem pins down exactly how fast: the density of primes near a large number xx is approximately 1/log⁡x1/\log x.

A Riemann-sum widget with n subintervals, used as a visual analogy for how the logarithmic integral $\operatorname{li}(x) = \int_2^x \dfrac{dt}{\log t}$ accumulates area under $1/\log t$; it is not an actual plot of $\operatorname{li}(x)$, since that function is not among this widget's preset integrands.
Sieve of Eratosthenes on 1..601..60: count the green primes in each row of 1010 — 44 primes in 1..101..10, 44 in 11..2011..20, then 2,2,3,22, 2, 3, 2 — illustrating how prime density thins out like 1/ln⁡x1/\ln x.

SchoolCounting primes: the function π(x)

Definition: Prime-counting function

π(x)\pi(x) denotes the number of primes pp with p≤xp \le x. For instance π(100)=25\pi(100) = 25: the primes up to 100100 are 2,3,5,7,…,972,3,5,7,\ldots,97.

π(x)=#{ p≤x:p prime }\pi(x) = \#\{\, p \le x : p \text{ prime} \,\}

In 1792, at age fifteen, Carl Friedrich Gauss conjectured — from studying tables of primes by hand — that π(x)\pi(x) is well approximated by the logarithmic integral li⁡(x)=∫2xdtlog⁡t\operatorname{li}(x) = \int_2^x \dfrac{dt}{\log t}, and equivalently, that the density of primes near xx behaves like 1/log⁡x1/\log x. The precise asymptotic statement is:

π(x)∼xlog⁡x\pi(x) \sim \dfrac{x}{\log x}
π(x) against the two classical estimates
xπ(x)x / ln xli(x)
1044.36.8
1002521.730.1
1,000168144.8177.6
10,0001,2291,085.71,246.1

UndergraduateAn elementary bound, and the full theorem

Let θ(x)=∑p≤xlog⁡p\theta(x) = \sum_{p \le x} \log p. Then θ(n)<(log⁡4) n\theta(n) < (\log 4)\, n for every integer n≥1n \ge 1.

Why is it true?

Before Hadamard and de la Vallée Poussin's 1896 analytic proof, Chebyshev (1852) already showed elementarily, using nothing but binomial coefficients, that the count of primes is trapped within a constant factor of x/log x. This bound is the key elementary ingredient later inputs to any proof of the full theorem, and its central-binomial-coefficient trick is the same one behind Erdős's famous elementary proof of Bertrand's postulate.

Proof

We use strong induction on nn. Base cases n=1,2n=1,2 are immediate: θ(1)=0\theta(1)=0 and θ(2)=log⁡2<log⁡4\theta(2)=\log 2 < \log 4.

For the inductive step, suppose the bound holds for every positive integer smaller than nn. If n>2n>2 is even, nn is not prime, so θ(n)=θ(n−1)<(log⁡4)(n−1)<(log⁡4)n\theta(n)=\theta(n-1) < (\log4)(n-1) < (\log4)n by the induction hypothesis applied to n−1n-1.

If n=2m+1n=2m+1 is odd, consider the central binomial-type coefficient (2m+1m)=(2m+1)!m! (m+1)!\binom{2m+1}{m}=\dfrac{(2m+1)!}{m!\,(m+1)!}. It appears twice among the 22m+12^{2m+1} terms of the binomial expansion of (1+1)2m+1(1+1)^{2m+1} (once as (2m+1m)\binom{2m+1}{m}, once as (2m+1m+1)\binom{2m+1}{m+1}, and these are equal), so 2(2m+1m)≤22m+12\binom{2m+1}{m} \le 2^{2m+1}, giving (2m+1m)≤4m\binom{2m+1}{m} \le 4^m.

Every prime pp with m+1<p≤2m+1m+1 < p \le 2m+1 divides the numerator (2m+1)!(2m+1)! but divides neither m!m! nor (m+1)!(m+1)! (since p>m+1p>m+1), so pp divides (2m+1m)\binom{2m+1}{m}. Hence the product of all such primes divides (2m+1m)\binom{2m+1}{m}, so ∏m+1<p≤2m+1p≤(2m+1m)≤4m\prod_{m+1<p\le 2m+1} p \le \binom{2m+1}{m} \le 4^m, i.e. θ(2m+1)−θ(m+1)≤(log⁡4) m\theta(2m+1)-\theta(m+1) \le (\log 4)\,m.

By the induction hypothesis applied to m+1<nm+1<n, θ(m+1)<(log⁡4)(m+1)\theta(m+1) < (\log4)(m+1). Adding, θ(n)=θ(2m+1)<(log⁡4)(m+1)+(log⁡4)m=(log⁡4)(2m+1)=(log⁡4)n\theta(n)=\theta(2m+1) < (\log4)(m+1) + (\log4)m = (\log4)(2m+1) = (\log4)n, completing the induction.

As x→∞x \to \infty, π(x)∼xlog⁡x\pi(x) \sim \dfrac{x}{\log x}; equivalently π(x)/li⁡(x)→1\pi(x)/\operatorname{li}(x) \to 1.

Why is it true?

Chebyshev's bound above pins π(x) to within a constant factor of x/log x, but "asymptotic to" is a much stronger claim: the ratio π(x)/(x/log x) must tend to exactly 1, not just stay bounded. Closing that gap from "bounded" to "exactly 1" needed an entirely different idea — Riemann's 1859 insight that the distribution of primes is encoded in the complex zeros of the zeta function ζ(s).

Proof

This proof is a logical sketch of the analytic route, not a self-contained derivation — it needs complex analysis introduced later in the curriculum (see the topic on the Riemann zeta function for the details). The argument has three stages.

Stage 1 (reduce to θ): a routine partial-summation argument shows π(x)∼x/log⁡x\pi(x) \sim x/\log x is equivalent to θ(x)∼x\theta(x) \sim x, where θ(x)=∑p≤xlog⁡p\theta(x)=\sum_{p\le x}\log p as in Chebyshev's bound above.

Stage 2 (encode θ via ζ): Riemann's explicit formula expresses θ(x)\theta(x) (more precisely the closely related ψ(x)=∑pk≤xlog⁡p\psi(x)=\sum_{p^k\le x}\log p) almost exactly in terms of the zeros of ζ(s)=∑nn−s=∏p(1−p−s)−1\zeta(s)=\sum_n n^{-s}=\prod_p(1-p^{-s})^{-1}: the leading term xx comes from ζ\zeta's simple pole at s=1s=1, and every zero ρ=β+iγ\rho=\beta+i\gamma of ζ\zeta contributes an oscillating error term of size roughly xβx^{\beta}.

Stage 3 (the key nonvanishing fact): ψ(x)∼x\psi(x)\sim x — and hence the theorem — holds if and only if no zero has β=1\beta=1, i.e. ζ(1+it)≠0 for all t∈R\zeta(1+it) \ne 0 \text{ for all } t \in \mathbb{R}. Hadamard and de la Vallée Poussin proved this nonvanishing independently in 1896, using an elementary trigonometric inequality (3+4cos⁡θ+cos⁡2θ≥03+4\cos\theta+\cos2\theta\ge0) applied to log⁡∣ζ(σ)3ζ(σ+it)4ζ(σ+2it)∣\log|\zeta(\sigma)^3\zeta(\sigma+it)^4\zeta(\sigma+2it)| as σ→1+\sigma\to1^+: a zero at 1+it1+it would force this expression to −∞-\infty, which the inequality forbids. Newman's 1980 proof streamlines Stage 3's consequences into a short Tauberian argument, but the logical backbone — pole at 11, zeros elsewhere, nonvanishing on the line Re⁡(s)=1\operatorname{Re}(s)=1 — is exactly as Riemann and Hadamard laid it out.

UndergraduateReal-World Applications and Worked Examples

The prime number theorem is not just theoretical: cryptographic software that generates RSA keys, and cryptanalysts who estimate how hard those keys are to break, both rely directly on knowing how densely primes are packed near a given size. The theorem's density estimate 1/log(x) tells you, on average, how many random odd numbers you must test before stumbling on a prime.

Example: How many random tries to find a 512-bit RSA prime?

An RSA key-generation routine picks random odd 512-bit numbers (near N=2512N=2^{512}) and primality-tests each until one is prime. Using the prime number theorem's density estimate, how many odd candidates should it expect to test on average?

Solution

By the theorem, near NN the density of primes among all integers is about 1/log⁡N1/\log N. Restricting to odd numbers doubles that density (even numbers are never prime past 22), so the density among odd candidates is about 2/log⁡N2/\log N.

Here log⁡N=log⁡(2512)=512log⁡2≈512×0.6931≈354.9\log N = \log(2^{512}) = 512\log 2 \approx 512 \times 0.6931 \approx 354.9. So the density is about 2/354.9≈0.005632/354.9 \approx 0.00563, i.e. roughly 11 in 177177 odd numbers near this size is prime.

If each candidate is an independent Bernoulli trial with this success probability, the expected number of trials until the first success is 1/p≈1771/p \approx 177. This is exactly why real RSA implementations report needing on the order of a few hundred primality tests (with a fast sieve pre-filtering obvious composites) to generate each large prime.

Example: Estimating trial-division cost when factoring a semiprime

A cryptanalyst wants a rough sense of how many candidate divisors trial division must check to factor a hard 100-digit semiprime NN (a product of two roughly equal primes), by testing all primes up to N\sqrt{N}. Using the prime number theorem, estimate how many primes that is.

Solution

NN has 100100 digits, so N≈10100N \approx 10^{100} and N≈1050\sqrt{N} \approx 10^{50}. By the prime number theorem, π(N)≈N/log⁡N\pi(\sqrt{N}) \approx \sqrt{N}/\log\sqrt{N}.

Here log⁡N=log⁡(1050)=50log⁡10≈50×2.3026≈115.1\log\sqrt{N} = \log(10^{50}) = 50\log 10 \approx 50 \times 2.3026 \approx 115.1. So π(N)≈1050/115.1≈8.7×1047\pi(\sqrt{N}) \approx 10^{50}/115.1 \approx 8.7\times10^{47}.

That astronomically large count — far beyond what any computer could ever enumerate, let alone test — is exactly why trial division is useless against real cryptographic moduli, and why RSA's security rests on factoring being computationally infeasible even though no proof of that hardness is known; the prime number theorem is precisely what lets cryptographers quantify "astronomically large" instead of just gesturing at it.

What does π(x) ~ x/log x mean, precisely?

Rounded to the nearest integer, what is x/ln x at x = 10,000 (ln 10000 ≈ 9.210)?

The 1896 proofs of the prime number theorem by Hadamard and de la Vallée Poussin both rest on which fact?

By the density estimate 2/log⁡N2/\log N for odd numbers near N, roughly what fraction of odd 2048-bit numbers is prime (log⁡(22048)≈1419.8\log(2^{2048}) \approx 1419.8)?

References

  1. MacTutor History of Mathematics, University of St Andrews (2021). Prime numbers (history)
  2. Donald J. Newman (1980). Simple analytic proof of the prime number theorem · DOI:10.1080/00029890.1980.11995126