Last active
June 22, 2020 04:36
-
-
Save musou1500/57830e18a49356375730bc933805f563 to your computer and use it in GitHub Desktop.
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
class Eratosthenes { | |
private: | |
vector<bool> is_prime_; | |
public: | |
Eratosthenes(int max_n): is_prime_(max_n + 1, true) { | |
is_prime_[0] = is_prime_[1] = false; | |
for (int i = 2; i < is_prime_.size(); i++) { | |
if (!is_prime_[i]) { | |
continue; | |
} | |
for (int j = i * 2; j < is_prime_.size(); j += i) { | |
is_prime_[j] = false; | |
} | |
} | |
} | |
operator()(int n) { | |
return is_prime_[n]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment