Last active
March 4, 2018 18:47
-
-
Save kimwalisch/28b1308ecbf33260bb2e243fab3459b0 to your computer and use it in GitHub Desktop.
Set the segment size in the segmented sieve of Eratosthenes
This file contains hidden or 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
| /// Set your CPU's L1 data cache size (in bytes) here | |
| const int64_t L1D_CACHE_SIZE = 32768; | |
| /// Generate primes using the segmented sieve of Eratosthenes. | |
| /// This algorithm uses O(n log log n) operations and O(sqrt(n)) space. | |
| /// @param limit Sieve primes <= limit. | |
| /// | |
| void segmented_sieve(int64_t limit) | |
| { | |
| int64_t sqrt = (int64_t) std::sqrt(limit); | |
| int64_t segment_size = std::max(sqrt, L1D_CACHE_SIZE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment