Galebickosikasa

Untitled

Aug 3rd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. template<size_t N>
  6. class IsPrime {
  7. public:
  8. constexpr IsPrime() : is_not_prime_() {
  9. is_not_prime_[0] = true;
  10. is_not_prime_[1] = true;
  11. for (size_t i = 2; i <= N; i++) {
  12. if (is_not_prime_[i]) {
  13. continue;
  14. }
  15. for (size_t j = i + i; j <= N; j += i) {
  16. is_not_prime_[j] = true;
  17. }
  18. }
  19. }
  20.  
  21. bool operator[](size_t num) const {
  22. return !is_not_prime_[num];
  23. }
  24.  
  25. private:
  26. bool is_not_prime_[N + 1];
  27. };
  28.  
  29. constexpr IsPrime<(int)2e7 + 20> is_prime;
  30.  
  31. int main() {
  32. int n;
  33. cin >> n;
  34. cout << is_prime[n] << "\n";
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment