Last active
March 6, 2018 13:36
-
-
Save kimwalisch/77553c9dbd2e67e3961a722c9d23e958 to your computer and use it in GitHub Desktop.
Segmented bit sieving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sieve segment using bit array | |
for (std::size_t i = 0; i < primes.size(); i++) | |
{ | |
int64_t j = multiples[i]; | |
for (int64_t k = primes[i] * 2; j < segment_size; j += k) | |
sieve[j >> 4] &= unset_bit[j & 15]; | |
multiples[i] = j - segment_size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment