As noted here, both PrimePi
and Prime
are documented as having their limits somwhere around $10^{15}.$ PrimeQ
and NextPrime
on the other hand don't seem to be so restricted. Is the following a reliable way of getting around that for short intervals of primes at greater heights?
pGAPS[r1_, r2_] :=
If[r1 < 3,
"start range must be > 2",
With[{bb = Split @ PrimeQ @ Range[r1, r2]},
With[{cc = If[bb[[1, 1]] == False, bb[[;; ;; 2]], bb[[2 ;; -1 ;; 2]]]},
Most @ Rest @ (Length @ #& /@ cc + 1)]]]
With[{a = 10^20, b = 10^20 + 10^4}, NextPrime[a] + Accumulate @ pGAPS[a, b]]
If so, Is there a more efficient way?
With[{a = #1, b = #2}, Rest@NestWhileList[NextPrime, NextPrime[a], # <= b &]] &
- simpler and as fast... $\endgroup$