Kolton Ndoj

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.

π(x)∼xln⁡x\pi(x)\sim\frac{x}{\ln x}

What the symbols mean

π(x)\pi(x)
the number of primes up to x (nothing to do with 3.14)
ln⁡x\ln x
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.

Graph for How many primes are there up to x? 2100300
The estimate x over ln x. The true count at 100 is 25 where the curve says about 22, and the true count is a staircase that hugs the curve. (drawn with the default slider values — move the sliders live)

Try it yourself

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.

Related

Play with it live →

Math · Number theory · Stretch