Advertisement
Mirbek

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

Jan 5th, 2022
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 3;
  6. const long long M = 1e12;
  7.  
  8. int pr[N];
  9.  
  10. int main(){
  11.     vector <long long> v;
  12.     for (int i = 2; i < N; i++) {
  13.         if (pr[i] == 0) {
  14.             long long x = i;
  15.             while (x * i <= M) {
  16.                 x = x * i;
  17.                 v.push_back(x);
  18.             }
  19.             if (1ll * i * i >= N) continue;
  20.             for (int j = i * i; j < N; j += i) {
  21.                 pr[j]++;
  22.             }
  23.         }
  24.     }
  25.  
  26.     int tt;
  27.     cin >> tt;
  28.  
  29.     while (tt--) {
  30.         long long low, high;
  31.         cin >> low >> high;
  32.  
  33.         int cnt = 0;
  34.         for (long long x : v) {
  35.             if (x >= low && x <= high)
  36.                 cnt++;
  37.         }
  38.  
  39.         cout << cnt << endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement