Advertisement
AlbertMourato

Untitled

Dec 7th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll primo[1000000];
  5. ll vetor[1000000];
  6. int main() {
  7.     //freopen("in.txt", "r", stdin);
  8.     //freopen("out.txt", "w", stdout);
  9.     //fazendo crivo
  10.     for(ll i = 2;i<=1000000;i++){
  11.         primo[i]=1;
  12.     }
  13.     for(ll i = 2;i<=1000000;i++){
  14.         if(primo[i]){
  15.             for(ll j = 2*i;j<=1000000;j+=i){
  16.                 primo[j] = 0;
  17.             }
  18.         }
  19.     }
  20.     int aux = 0;
  21.     for(ll i = 0;i<=1000000;i++){
  22.         if(primo[i]) aux++;
  23.         vetor[i] = aux;
  24.     }
  25.     int t;
  26.     ll auxiliar, a, b, s = 0;
  27.     cin>>t;
  28.     while(t>0){
  29.         auxiliar = 0;
  30.         cin>>a>>b;
  31.         s = 0;
  32.         a = sqrt(a-1);
  33.         b = sqrt(b);
  34.         s = vetor[b]-vetor[a];
  35.         cout<<s<<"\n";
  36.         t--;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement