How many primes are there up to x?
Primes look random, yet their thinning-out follows an exact law: about one in every ln x numbers near x is prime.
What the symbols mean
- the number of primes up to x (nothing to do with 3.14)
- the natural logarithm of x
Why it works — the picture
Count: 25 primes below 100, 168 below 1000, 78498 below a million. The guess x/ln x gives 21.7, 145 and 72382, which is too low but with a relative error that shrinks to zero. Another way: the chance a number near x is prime is about 1/ln x, so the density thins slowly like a logarithm. Primes never run out, but they get lonelier and lonelier.
Try it yourself
- Count the primes below 50 (15) and compare to the estimate 12.8.
- Make a sieve of Eratosthenes up to 100.
- Estimate how many primes have 20 digits.
Where it’s used in real life
Choosing primes of the right size for encryption relies on it: to find a 300-digit prime, you test about 700 candidates.
The story behind it
Gauss guessed it as a teenager; it was proved independently by Hadamard and de la Vallee Poussin in 1896.