math - Is there a way to find the approximate value of the nth prime? -


Is there any work that n will return the prime minister's estimated value? I think this would be something like an approximate inverted main count function. For example, if I give this function 25, then it will return a number around 100, or if I give this function 1000, then it will return a number around 8000. I do not care if the return number is dominant or not, but I want it to be fast (hence n do not generate major numbers before n

I like it so that I can generate the first n primary numbers by using a sieve (or), n th For approximation, ideally, the value of the actual n does not consider reducing the value of the principal.

(Update: For a good method, see n to find the upper limit of the prime number.)

Strict range:

Fixed priceless small primes_small [] = {0,2,3,5,7,11}; Steady unsigned long nth_prime_upper (unsigned long n) {double fn = (double) n; Double flogn, flog2n, upper; If (n & lt; 6) returns primes_small [n]; Flagon = log (n); Flog2n = log (flogn); If (n> = 688383) / * Dusart 2010 page 2 * / upper = FN * (flogn + flog2n - 1.0 + ((flog2n-2.00) / flogn)); Else if (n> = 178974) / * Dusart 2010 page 7 * / upper = FN * (flogn + flog2n - 1.0 + ((flog2n-1.95) / flogn)); Else if (n> = 39017) / * Dusart 1999 page 14 * / upper = FN * (flogn + flog2n - 0.9484); Robin for Else / * 6 9 016 Modified _only_ * / upper = fn * (flogn + 0.6000 * flog2n) from 1983; If (upper & gt; = (double) ULONG_MAX) {/ * adjust it according to your type and exception method * / if (n & lt; = 425656284035217743UL) 18446744073709551557UL; Fprintf (stderr, "nth_prime_upper overflow \ n"; exit (-1);} return (unsigned long) seat (upper);}

This should never be less than the actual nth_prime , Should work for any 64-bit input, and there should be an order of greater intensity than before the formula given by Robin or (or complex limit-limited formulas of Wimbal). For my use I have a small small The pram table is so tight that the final estimate a bit more. Technically, we can use floor () instead of seat (), but I have concerns about accuracy.

EDIT: Another option to improve it is good prime borders ( Like Axler 2014) and are doing a binary search on them. For this method, my code takes ~ 10x longer than the above (still under milliseconds), but decreasing the error percentage from the sequence of intensity Can .

If you want an estimate for the nth Prime Minister, you can do this:

  • See Cipolla 1902 (see page 12 or I get three posts (m = 2) Plus th odd order correction factor can be useful, but with more words it oscillates too much. The formula shown in the Wikipedia link is this formula (with M = 2), it will get better results by using two-inverse reverse or revenient r.
  • Calculate the upper and lower limit of Dusart 2010 and average the result. Not very bad, though I doubt using the weighted average would work better because the boundary is not equally tight. Since Li (N) is a decent estimate prime count, the inversion is a decent nth_prime approximation, and all else can be done as fast as a binary search on the function.
  • Inversion Riemann R function is the closest average approximation which I know is appropriate.

Finally, if you have a very fast original counting method like one of the LMO implementations (now there are three open-source implementations), you can write a fast accurate nth_prime method Are there. 10 ^ 10 Prime Minister's calculations can be done in a few milliseconds, and in few seconds 10 ^ 13 (on modern fast machine). Estimation on almost all sizes is extremely fast and so far we work for a large number, but everyone has a different idea that means "big".


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -