Advertisement
bappi2097

C. Odd Is Real

Sep 2nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef unsigned long long int ull;
  4. map<ull,bool>mp;
  5. map<ull,bool>::iterator it;
  6. vector<ull> result2;
  7. vector<ull>::iterator it1,it2,it3,it4;
  8. void sqrDouble()
  9. {
  10.     mp[1]=true;
  11.     mp[2]=true;
  12.     for(ull i=2;i<=31623;i++)
  13.     {
  14.         if(!mp[i*i])
  15.         {
  16.             for(ull j=i*i;sqrt(j)<=1000000000 && !mp[j];j*=j)
  17.             {
  18.                 mp[j]=true;
  19.                 if(!mp[j*2])mp[j*2]=true;
  20.             }
  21.         }
  22.     }
  23.     it=mp.begin();
  24.     it++;
  25.     for(it;it!=mp.end();it++)result2.push_back(it->first);
  26.     return;
  27. }
  28. int main()
  29. {
  30.     ios_base::sync_with_stdio(false);
  31.     cin.tie(NULL);
  32.     #ifndef ONLINE_JUDGE
  33.     freopen("input.cpp","r",stdin);
  34.     freopen("output.cpp","w",stdout);
  35.     #endif // ONLINE_JUDGE
  36.     sqrDouble();
  37.     int t;
  38.     cin>>t;
  39.     for(int i=0;i<t;i++)
  40.     {
  41.         ull l,r,x,y;
  42.         cin>>l>>r;
  43.         it1=upper_bound(result2.begin(),result2.end(),l);
  44.         it2=lower_bound(result2.begin(),result2.end(),l);
  45.         long long a=(it1 - result2.begin())+1;
  46.         long long b=(it2 - result2.begin())+1;
  47.         if(a != b)
  48.             x = b;
  49.         else x=a;
  50.  
  51.         it3=upper_bound(result2.begin(),result2.end(),r);
  52.         it4=lower_bound(result2.begin(),result2.end(),r);
  53.         long long c = (it3 - result2.begin())+1;
  54.         long long d = (it4 - result2.begin())+1;
  55.         if(c != d)
  56.             y=c;
  57.         else y=d;
  58.         int ans=y-x;
  59.         cout<<"Case "<<i+1 <<": "<<ans<<endl;
  60.     }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement