Prime numbers thin out as numbers grow, in a way that is described by the prime number theorem. The prime number theorem calculator takes a limit x, an interval length and a position n and gives two estimates of the number of primes up to x, the chance that a number near x is prime, the average gap between primes, the expected number of primes in an interval and an estimate of the n-th prime.
How the calculation works
- Simple estimate of the number of primes up to x: π(x) ≈ x ÷ ln x. This is the prime number theorem, and the estimate is always a bit low.
- Better estimate: π(x) ≈ x ÷ (ln x − 1). The −1 corrects most of the error of the simple formula.
- Chance that a number near x is prime = 1 ÷ ln x, and the average gap between consecutive primes is about ln x. The expected primes in an interval of length L is L ÷ ln x.
- n-th prime ≈ n × (ln n + ln ln n − 1). It follows from inverting the better estimate.
Example
For x = 1,000,000, ln x = 13.8155. The simple estimate gives 1,000,000 ÷ 13.8155 ≈ 72,382 primes, and the better one 1,000,000 ÷ 12.8155 ≈ 78,030. The exact count is 78,498, so the better estimate is within 0.6%. A number near one million is prime with a chance of 1 ÷ 13.8155 ≈ 7.24%, with an average gap of about 13.8, so an interval of 1,000 numbers holds about 72.4 primes. The 10,000th prime is estimated at 104,307; the true value is 104,729.
Why it matters
The theorem links number theory to simple analysis, and it is a common topic in mathematics courses. The estimates are also practical: cryptography needs large random primes, and the chance that a random number of a given size is prime tells you how many candidates must be tested.
Good to know
All the results are estimates and not exact counts. They are very good for large x and weaker for small x. The calculator does not test whether a given number is prime, and it does not list primes. For exact counts use a sieve, and for very large x use the logarithmic integral.
Related tools
The GCD and LCM calculator covers the divisors of two numbers and the Fibonacci calculator explores another famous sequence.