Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     vector<bool> is_prime(pow(10, 6) + 1, true);
  9.     vector<long long int> ilosci={0, 0};
  10.     for (long long int i = 2; i <= pow(10, 6) ; ++i){
  11.         if(is_prime[i]){
  12.             ilosci.push_back(ilosci[i-1] + 1);
  13.             for (long long int j = i*2; j <= pow(10, 6); j += i) {
  14.                 is_prime[j] = false;
  15.             }
  16.         } else{
  17.             ilosci.push_back(ilosci[i-1]);
  18.         }
  19.     }
  20.  
  21.     int n;
  22.     cin >> n;
  23.  
  24.     vector<pair<int, int>> args;
  25.  
  26.     for (int i = 0; i < n; ++i) {
  27.         int a, b;
  28.         cin >> a >> b;
  29.         args.emplace_back(make_pair(a, b));
  30.     }
  31.  
  32.     for (auto a : args) {
  33.         cout<< ilosci[a.second] - ilosci[a.first-1] << endl;
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement