AlbertMourato

Untitled

Dec 6th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 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("out.txt", "w", stdout);
  8.     //fazendo crivo
  9.     for(ll i = 2;i<=1000000;i++){
  10.         primo[i]=1;
  11.     }
  12.     for(ll i = 2;i<=1000000;i++){
  13.         if(primo[i]){
  14.             for(int j = 2*i;j<=1000000;j+=i){
  15.                 primo[j] = 0;
  16.             }
  17.         }
  18.     }
  19.     int t;
  20.     ll a, b, s = 0;
  21.     cin>>t;
  22.     ll aux;
  23.     while(t>0){
  24.         cin>>a>>b;
  25.         s = 0;
  26.         ll aa = a;
  27.         a = sqrt(a);
  28.         if(pow(a,2)!=aa) a++;
  29.         b = sqrt(b);
  30.         for(ll i= a;i<=b;i++){
  31.             if(primo[i])s++;
  32.         }
  33.         cout<<s<<"\n";
  34.         t--;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment