Number TheoryPrimes and Factorization

How Common Are Primes?

The prime number theorem: there are about x/ln x primes up to x. Primes thin out, and n! + 2, …, n! + n is a run of n − 1 composite numbers.

Not started Jump to practice

There are infinitely many primes, but how many up to a given point? Write $\pi(x)$ for the number of primes $p \le x$ (this $\pi$ has nothing to do with $3.14159\dots$). So $\pi(10) = 4$ and $\pi(100) = 25$.

The prime number theorem (proved in 1896 by Hadamard and de la Vallée Poussin): $$\pi(x) \sim \frac{x}{\ln x}, \quad\text{meaning}\quad \lim_{x \to \infty} \frac{\pi(x)}{x / \ln x} = 1.$$ Here $\ln$ is the natural logarithm. An equivalent way to say it: near a large number $x$, roughly one number in $\ln x$ is prime.

The exact count $\pi(x)$ (a staircase) and the estimate $x/\ln x$. The gap between them grows, but the ratio creeps toward 1.
Exact counts against the estimate.
$x$$\pi(x)$$x / \ln x$ratio
$10^{3}$1681451.16
$10^{4}$1,2291,0861.13
$10^{6}$78,49872,3821.08
$10^{9}$50,847,53448,254,9421.05

Why it works

Why a logarithm? Each extra digit makes primes a little rarer, by about the same amount. Among the 900 three-digit numbers there are $168 - 25 = 143$ primes, about 1 in 6.3, and $\ln 500 \approx 6.2$. Among the 900,000 six-digit numbers there are $78{,}498 - 9{,}592 = 68{,}906$ primes, about 1 in 13, and $\ln 550{,}000 \approx 13.2$. The density $1/\ln x$ captures this slow thinning. (The proof uses complex analysis and is far beyond this course.)

Worked example: Using the estimate

Estimate $\pi(10^{6})$ with $x/\ln x$, and compare with the true value $78{,}498$.
  1. $\ln 10^{6} = 6 \ln 10 \approx 6 \cdot 2.302585 = 13.8155$.
  2. $10^{6} / 13.8155 \approx 72{,}382$.
  3. The estimate is about $6{,}100$ too low, roughly $8\%$ of the true count. At $10^{9}$ it is $5\%$ low.

Answer: About $72{,}382$, an underestimate.

Worked example: Long gaps between primes

Find five consecutive composite numbers.
  1. Take $6! = 720$ and look at $722, 723, 724, 725, 726$, that is, $6! + j$ for $j = 2, \dots, 6$.
  2. $j$ divides $6!$ and divides $j$, so $j \mid 6! + j$: $722 = 2 \cdot 361$, $723 = 3 \cdot 241$, $724 = 4 \cdot 181$, $725 = 5 \cdot 145$, $726 = 6 \cdot 121$.
  3. The same trick with $n! + 2, \dots, n! + n$ gives $n - 1$ composites in a row, so gaps between primes can be as long as you like.

Answer: $722$ through $726$.

Worked example: Why cryptographers care

About what fraction of 100-digit numbers are prime?
  1. Near $x = 10^{100}$, about one number in $\ln 10^{100} = 100 \ln 10 \approx 230$ is prime.
  2. So a random 100-digit odd number is prime with probability about $2/230 = 1/115$: a computer finds one after about a hundred tries. RSA keys are made this way.

Answer: About $1$ in $230$.

Common mistake

Treating $x/\ln x$ as the exact count. It is an estimate: $\pi(10^{6}) = 78{,}498$, while $10^{6}/\ln 10^{6} \approx 72{,}382$. The theorem promises only that the ratio tends to 1, so the relative error shrinks. The difference itself keeps growing.

Key idea

$\pi(x) \sim x/\ln x$: the ratio tends to 1. Near $x$, about one number in $\ln x$ is prime; primes thin out, slowly.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Number Theory.

Sources and further reading

  • William Stein, Elementary Number Theory: Primes, Congruences, and Secrets (Springer, 2009; free online edition), chapter 1, Prime Numbers (how many primes are there?)
  • MIT OpenCourseWare 18.781 Theory of Numbers (Spring 2012), lecture notes on the distribution of primes
@teddyrookbook GitHub