Skip to content

Instantly share code, notes, and snippets.

@musou1500
Last active June 22, 2020 04:36
Show Gist options
  • Save musou1500/57830e18a49356375730bc933805f563 to your computer and use it in GitHub Desktop.
Save musou1500/57830e18a49356375730bc933805f563 to your computer and use it in GitHub Desktop.
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