1 /* 2 Copyright (C) 2010 Fredrik Johansson 3 4 This file is part of FLINT. 5 6 FLINT is free software: you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License (LGPL) as published 8 by the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. See <http://www.gnu.org/licenses/>. 10 */ 11 12 #include <gmp.h> 13 #include "flint.h" 14 #include "ulong_extras.h" 15 16 n_nth_prime_bounds(mp_limb_t * lo,mp_limb_t * hi,ulong n)17void n_nth_prime_bounds(mp_limb_t *lo, mp_limb_t *hi, ulong n) 18 { 19 int bits, ll; 20 double llo, lhi; 21 22 /* Lower and upper bounds for ln(n) */ 23 bits = FLINT_BIT_COUNT(n); 24 llo = (bits-1) * 0.6931471; 25 lhi = bits * 0.6931472; 26 27 /* Lower bound for ln(ln(n)) */ 28 if (n < 16) ll = 0; 29 else if (n < 1619) ll = 1; 30 else if (n < 528491312) ll = 2; 31 else ll = 3; 32 33 *lo = (mp_limb_t) (n * (llo + ll - 1)); 34 *hi = (mp_limb_t) (n * (lhi + (ll+1) - (n >= 15985 ? 0.9427 : 0.0))); 35 } 36