Max Alekseyev on Thu, 08 Jan 2026 16:37:18 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: primepi(2^35)


Here is a simple script that provides an interface to the state-of-art primecount tool available from
https://github.com/kimwalisch/primecount

inline(primecountbin = "~/projects/primepi/primecount ");
{ PrimePi(n) = if(n<default(primelimit), primepi(n), extern(concat(primecountbin,Str(n))) ); }
{ NthPrime(n) = extern(concat([primecountbin,"-n ",Str(n)])); }

Regards,
Max



On Tue, Jan 6, 2026 at 12:58 PM Loïc Grenié <loic.grenie@gmail.com> wrote:
On Tue 6 Jan, 2026, at 18:28, Ruud H.G. van Tol wrote:

? default(primelimit)
% 2000000000


? primepi(2^35)
cpu time = 18,133 ms, real time = 18,162 ms.
% 1480206279

? primepi(10^11)
cpu time = 4,744 ms, real time = 4,752 ms.
% 4118054813


Q: Why is the bigger value returned faster?

      Because there is a table of precomputed pairs primepi/prime. If you fall near one
  of the precomputed values, the computation is faster.

          Happy new year,

                  Loïc

 

? prime(1480206279)
cpu time = 18,874 ms, real time = 18,937 ms.
% 34359738337

? prime(4118054813)
cpu time = 4,909 ms, real time = 4,917 ms.
% 99999999977