7

1

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?

Related? (3327)

– dr.blochwave – 2015-09-07T07:46:10.797@blochwave - thanks for link - have incorporated into question now :) – martin – 2015-09-07T07:50:09.600

Also note this discussion over on Wolfram Community

– dr.blochwave – 2015-09-07T07:52:46.440@blachwave - thanks, hadn't seen that one - will give it a read – martin – 2015-09-07T07:53:55.787

5Why not just

`With[{a = #1, b = #2}, Rest@NestWhileList[NextPrime, NextPrime[a], # <= b &]] &`

- simpler and as fast... – ciao – 2015-09-07T09:16:18.030@ciao nice :) thanks - definitely simpler ! – martin – 2015-09-07T09:31:46.933