How do I find upper bound for nth prime number?

1.9k Views Asked by At

I'm writing a program that finds the nth prime number, so if n was 10, the answer would be 29. I need to find an upper bound to search through though so if n was 10, the upper bound would be 30 (or any number before the next prime number which is 31).

Any ideas?

1

There are 1 best solutions below

2
On

The number of primes below a given number, $\pi(x)$ can be estimated by:

$\pi(x) \approx \frac{x}{\ln(x)}$.

If you can find a "good" way to invert that function (and add maybe 20% uncertainty in there for small numbers), you can find the estimated upper bound.