FLINT3.7.0-dev

n_nth_prime, n_nth_prime_bounds

Synopsis#include <flint/ulong_extras.h>
ulong n_nth_prime(ulong n)source
void n_nth_prime_bounds(ulong * lo, ulong * hi, ulong n)source

Return the nn-th prime pnp_n (with p1=2p_1 = 2; n=0n = 0 throws an exception), or set lo≤pn≤hi\mathit{lo} \le p_n \le \mathit{hi}.

n_nth_prime makes sure the table of cached primes is large enough and looks up the entry. n_nth_prime_bounds does not check for overflow, so its bounds are meaningless for large nn. It uses the estimates, valid for n>5n > 5,

pn>n(ln⁡n+ln⁡ln⁡n−1),pn<n(ln⁡n+ln⁡ln⁡n),pn<n(ln⁡n+ln⁡ln⁡n−0.9427)(n≥15985).\begin{aligned} p_n &> n (\ln n + \ln \ln n - 1), \\ p_n &< n (\ln n + \ln \ln n), \\ p_n &< n (\ln n + \ln \ln n - 0.9427) \quad (n \ge 15985). \end{aligned}

The first inequality is due to Dusart [Dus1999] and the last to Massias and Robin [MasRob1996].

References#

  • [Dus1999] P. Dusart, "The kthk^{th} prime is greater than k(ln⁡k+ln⁡ln⁡k−1)k(\ln k+\ln \ln k-1) for k≥2k \ge 2," Math. Comp., 68:225 (January 1999) 411–415.
  • [MasRob1996] J. Massias and G. Robin, "Bornes effectives pour certaines fonctions concernant les nombres premiers," J. Theorie Nombres Bordeaux, 8 (1996) 215-242.
Cite this page

The FLINT team, “n_nth_prime, n_nth_prime_bounds (ulong_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/ulong_extras/n_nth_prime.html (generated 2026-11-02).