Advertisement
Mirbek

Простые числа

Jan 5th, 2022
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 3e5 + 3;
  6.  
  7. bool isPrime(int x) {
  8.     if (x < 2) return 0;
  9.     int sq = sqrt(x);
  10.     for (int i = 2; i <= sq; i++) {
  11.         if (x % i == 0) {
  12.             return false;
  13.         }
  14.     }
  15.     return true;
  16. }
  17.  
  18. int pr[N];
  19.  
  20. int main(){
  21.  
  22.     for (int i = 2; i < N; i++) {
  23.         if (pr[i] == 0) {
  24.             if (1ll * i * i >= N) continue;
  25.             for (int j = i * i; j < N; j += i) {
  26.                 pr[j] = 1;
  27.             }
  28.         }
  29.     }
  30.  
  31.     int left, right;
  32.     cin >> left >> right;
  33.  
  34.     int cnt = 0;
  35.     for (int i = left; i <= right; i++) {
  36.         if (pr[i] == 0) {
  37.             cout << i << endl;
  38.             cnt++;
  39.         }
  40.     }
  41.  
  42.     if (cnt == 0) {
  43.         cout << "Absent" << endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement