# 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:

1. What's a quick, simple, and approximate formula for $n$?
2. 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?

• is this really a prime number? Commented Jan 14, 2016 at 16:00
• @Dr.SonnhardGraubner Yes. Commented Jan 14, 2016 at 16:01
• Many good approximations are given on wikipedia about prime number theorem
– qwr
Commented Jan 14, 2016 at 16:06
• One could potentially win $1 million by answering your new question, so... Commented Jan 14, 2016 at 16:34 • @NajibIdrissi: I don't mean tweak it perfectly. I'll be happy with a slight improvement. For example, as in the link given by qwr, we have more terms as, $$\frac{p_n}{n} \approx \ln(n) + \ln\ln n - 1$$ or better, $$\frac{p_n}{n} \approx \ln(n) + \ln\ln n - 1 +\frac{\ln\ln n - 2}{\ln n}$$ Using these, how do we isolate$n$and express it in terms of$p_n$? Commented Jan 14, 2016 at 16:40 ## 4 Answers 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) • Oh, come on, almost 1000 reputation points and still not formatting your posts with MathJax? Commented Jan 14, 2016 at 21:40 • Happier? I think the lack of tables or tabs is a bigger issue. Commented Jan 14, 2016 at 21:58 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)}$• This is a good way to put it. – quid Commented Jan 14, 2016 at 16:03 • Ah, the prime counting function$\pi(x)$. Know a way to tweak this formula to make it more sharp? Commented Jan 14, 2016 at 16:10 • Although you never know enough in math, I think that if there were some refinement of the formula$\pi(x) \approx \frac{x}{log(X)}$, it would be quite known. Commented Jan 14, 2016 at 16:28 • @Piquito:$\operatorname{Li}(x)$is much sharper than$x/\log x.$Commented Jan 14, 2016 at 20:33 • Thank you, I have seen once about Li(x) but I have forgot it. Commented Jan 15, 2016 at 13:18 Much better, and given in the Wikipedia article is $$\pi(x )\approx Li(x) =\int_2^x \frac 1{\log t} \ dt$$ • $$\pi(x) = 3543419187\\ \text{Li}(x) \approx 3543431315\\ \frac{x}{\ln x} \approx 3396252652$$ As in the first answer, can we add more terms to make$\text{Li}(x)$even more accurate? Commented Jan 14, 2016 at 17:00 • @TitoPiezasIII: Probably not. It seems that the next term is oscillatory. In any case the oscillatory component is at least$\Theta_\pm(\sqrt x)/\log^kx$where$k$is some constant I forgot (maybe 2). Commented Jan 14, 2016 at 20:30 • Note that$\pi(x)$and$Li (x)$are very close. It is known that which is higher changes infinitely many times, so the error does oscillate. Commented Jan 15, 2016 at 0:07 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\%\$.

• This is quite indirect. The approach via the prime counting function seems superior.
– quid
Commented Jan 14, 2016 at 22:15