The $n$th prime number is $85489307341$. How to find $n$? Say you are given the $n$th prime number $p_n$, like $p_n = 85489307341$, but not $n$.
Questions:


*

*What's a quick, simple, and approximate formula for $n$?

*By adding more terms, can this formula be made more precise?


Edit: In reference to the answer below, how can we tweak $n = \pi(x) \approx \frac{x}{\log(x)}$ to make it more accurate?
 A: say nth_prime(3543419187)
85489307341

say prime_count(85489307341)
3543419187  # looks right

Note that prime counts at this size are quite cheap.  About 19 milliseconds on my laptop.  That's still over 1000x slower than the most complicated of the approximations below.
Percent difference from exact answer for various methods using this n, given in order of closeness for larger inputs:
$R(n)$  2.3e-7  very good approximation from Riemann's R function
${\rm li}(n)-{\rm li}(n^{0.5})/2$  1.7e-7  also very good from truncated R
${\rm li}(n)$  3.4e-6  very good
$(\pi_{\rm upper}(n)+\pi_{\rm lower}(n))/2$  9.5e-7  surprisingly good from average bounds, but it is all dependent on using tight bounds, and it doesn't keep up as size increases
$n/(\log(n)-1-1/\log(n))$  .00024  not horrible
$n/(\log(n)-1)$  .0019  meh
$n/\log(n)$  .042  ugh (but better than randomly guessing numbers)
A: For (1), you have for large $x$ that the number of primes less than or equal to $x$ is $\pi(x) \approx \frac{x}{\log(x)}$
A: Much better, and given in the Wikipedia article is $$\pi(x )\approx Li(x) =\int_2^x \frac 1{\log t} \ dt$$
A: Use one of the nice approximations for $p_n / n$ in terms of $n$ (from Wikipedia's PNT entry, say) and invert it iteratively.  For instance, start with
$$
p_n \approx n \left(\log n + \log\log n - 1 +\frac{\log\log n - 2}{\log n}\right). 
$$
Initialize $n_0=p_n$.  And then iterate:
$$
n_{i+1}=\frac{p_n}{\log n_i + \log\log n_i - 1 + \frac{\log\log n_i - 2}{\log n_i}}.
$$
This converges nicely if $p_n$ is large... in your case I find $n\approx 3.5431\times 10^9$, which differs from the exact answer of $n=3543419187$ by about $0.01\%$.
