Skip to content

Commit

Permalink
Fix minimum primeApprox
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jan 7, 2024
1 parent 71e2303 commit 5bf8fce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nthPrime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ uint64_t PrimeSieve::nthPrime(int64_t n, uint64_t start)
primeApprox = nthPrimeApprox(nApprox);
}

primeApprox = std::max(primeApprox, start);
if (primeApprox > 0)
avgPrimeGap = ilog(primeApprox) + 2;

Expand All @@ -69,8 +70,7 @@ uint64_t PrimeSieve::nthPrime(int64_t n, uint64_t start)
// countPrimes() and hence the initailization overhead of
// O(x^0.5 log log x^0.5) occurs only once (instead of twice) when
// using primesieve::iterator further down.
if (start < primeApprox &&
primeApprox - start > isqrt(primeApprox) / 10)
if (primeApprox - start > isqrt(primeApprox) / 10)
{
// Count primes > start
start = checkedAdd(start, 1);
Expand Down

0 comments on commit 5bf8fce

Please sign in to comment.