A Note on Algorithms for Computing $p_n$
Ansh Aggarwal
TL;DR
This paper analyzes several algorithmic strategies for computing the $n$-th prime $p_n$, contrasting a binary-search approach that leverages the prime-counting function $\pi(x)$ with sieve-based methods. Unconditionally, combining bounds for $p_n$ with the best known $\pi(x)$-evaluation yields a bound of $O(\sqrt{n}\,\log^4 n)$ for computing $p_n$. Sublinear and segmented sieves, given current knowledge of $p_n$ bounds, do not beat binary search asymptotically. Conditional on the Riemann Hypothesis and Cramér's conjecture, the authors construct a tighter interval around $\alpha$ with $\mathrm{li}(\alpha)=n$, enabling a sieve-based method that runs in $O(\sqrt{n}\,\log^{7/2} n\,\log\log n)$ time, which would surpass binary search under these assumptions. The results indicate that future improvements to prime-gap estimates could lead to provably faster, prime-finding algorithms.
Abstract
We analyze algorithms for computing the $n$th prime $p_n$ and establish asymptotic bounds for several approaches. Using existing results on the complexity of evaluating the prime-counting function $π(x)$, we show that the binary search approach computes $p_n$ in $O(\sqrt{n} \, (\log n)^4)$ time. Assuming the Riemann Hypothesis and Cramér's conjecture, we construct a tighter interval around li$^{-1}(n)$, leading to an improved sieve-based algorithm running in $O(\sqrt{n} \, (\log ^{7/2} n) \, \log \log n)$ time. This improvement, though conditional, suggests that further refinements to prime gap estimates may yield provably faster methods for computing primes.
