Commits

dafis  committed e0a2df9

Fix off-by-one error in nthPrime

If a = nthPrimeApprox n was congruent to 10, 16, 22 or 28 modulo 30, the index calculation yielded a too large result, hence if a+1 was prime, it was wrongly ignored. Using (strt-2) instead of a for the index calculation fixes it.

  • Participants
  • Parent commits 5c29897

Comments (0)

Files changed (1)

File Math/NumberTheory/Primes/Counting/Impl.hs

         rep | o0 < 0    = 0
             | otherwise = sum [1 | i <- [0 .. r2], ba `unsafeAt` i]
               where
-                o0 = a - vO - 7
+                o0 = strt - vO - 9   -- (strt - 2) - v0 - 7
                 r0 = fromInteger o0 `rem` 30
                 r1 = r0 `quot` 3
                 r2 = min 7 (if r1 > 5 then r1-1 else r1)