1

When seeking the nth prime, how would one determine (or approximate) $x$, given a $\pi(x)$ value?

I've read that $x / log(x)$ is a decent approximation of primes below $x$, but nothing about the reverse.

I'm seeking an algorithm that can be easily implemented.

JB0x2D1
  • 209
  • 1
    http://math.stackexchange.com/questions/1348247/inverse-of-prime-counting-function and http://mathoverflow.net/questions/131683/asymptotic-bounds-on-pi-1x-inverse-prime-counting-function – Henricus V. Apr 01 '16 at 03:20
  • 1
    $n$th prime number is approximately $n\ln n$. This follows from prime number theorem. – Wojowu Apr 01 '16 at 05:08

1 Answers1

2

For prime numbers $p_k$ you have $\pi(p_k)=k$, exactly.

Because the prime number theorem gives the approximation $p_k \sim k\log k,$ then the number $x$ for which $\pi(x)=k$ is approximately $k\log k$ with an known associated error.

Any $x$ in the interval $p_{k}\leq x<p_{k+1}$ gives $\pi(x)=k,$ so as you might expect,

$p_k\sim x\sim k\log k,$

and as you might or might not expect, $p_k\sim p_{k+1}.$ When implementing an algorithm using the p.n.t. approximation it may be important to keep the error in mind. Dusart's error bounds are very useful.

daniel
  • 10,141
  • Thanks. I thought I had read about k log k, but when I looked back, my eyes landed on x / log x and I got mixed up. I ended up increasing k by 13% and generating primes < n where n = k log k. I couldn't successfully implement Dusart's bounds. Why 13%? Because 12% didn't always yield a large enough n in my tests. code – JB0x2D1 Apr 01 '16 at 14:40