Skip to content

Commit

Permalink
Fix bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jan 8, 2024
1 parent 896c702 commit 64a1365
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 @@ -150,7 +150,7 @@ uint64_t PrimeSieve::negativeNthPrime(int64_t n, uint64_t start)
// we simply iterate over the primes until we find it.
if (countApprox >= n)
{
uint64_t dist = (n - countApprox) * avgPrimeGap(start);
uint64_t dist = (countApprox - n) * avgPrimeGap(start);
uint64_t stop = checkedAdd(start, dist);
primesieve::iterator iter(start, stop);
for (int64_t i = countApprox; i >= n; i--)
Expand All @@ -159,7 +159,7 @@ uint64_t PrimeSieve::negativeNthPrime(int64_t n, uint64_t start)
else // if (countApprox < n)
{
start = checkedSub(start, 1);
uint64_t dist = (countApprox - n) * avgPrimeGap(start);
uint64_t dist = (n - countApprox) * avgPrimeGap(start);
uint64_t stop = checkedSub(start, dist);
primesieve::iterator iter(start, stop);
for (int64_t i = countApprox; i < n; i++)
Expand Down

0 comments on commit 64a1365

Please sign in to comment.