Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- template<size_t N>
- class IsPrime {
- public:
- constexpr IsPrime() : is_not_prime_() {
- is_not_prime_[0] = true;
- is_not_prime_[1] = true;
- for (size_t i = 2; i <= N; i++) {
- if (is_not_prime_[i]) {
- continue;
- }
- for (size_t j = i + i; j <= N; j += i) {
- is_not_prime_[j] = true;
- }
- }
- }
- bool operator[](size_t num) const {
- return !is_not_prime_[num];
- }
- private:
- bool is_not_prime_[N + 1];
- };
- constexpr IsPrime<(int)2e7 + 20> is_prime;
- int main() {
- int n;
- cin >> n;
- cout << is_prime[n] << "\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment