Advertisement
Nayeemzaman

Untitled

Sep 2nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<long long>result1;
  5. vector<long long>result2;
  6. vector<long long>::iterator it1,it2,it3,it4;
  7.  
  8.  
  9. void squareroot()
  10. {
  11.     result1.push_back(1);
  12.     result1.push_back(2);
  13.     for(long long i=2; i<=31623; i++)
  14.     {
  15.         long long a=i*i;
  16.         result1.push_back(a);
  17.         long long b=a*2;
  18.         //long long s=sqrt(b);
  19.         //if(s*s != b)
  20.         result1.push_back(b);
  21.  
  22.         long long c=a*a;
  23.         result1.push_back(c);
  24.         long long d=c*2;
  25.         result1.push_back(d);
  26.         //result.push_back(b);
  27.     }
  28.     sort(result1.begin(),result1.end());
  29.     long long tmp = result1[0];
  30.     //result2.p(1);
  31.     //ps1.pb(2);
  32.     //ps1.pb(ps[0]);
  33.  
  34.     result2.push_back(1);
  35.     for(long long i=0; i<result1.size(); i++)
  36.     {
  37.         if(tmp!=result1[i]){
  38.             result2.push_back(result1[i]);
  39.             tmp =result1[i];
  40.         }
  41.     }
  42. }
  43.  
  44. int main()
  45. {
  46.     int n;
  47.     cin>>n;
  48.  
  49.  
  50.     squareroot();
  51.  
  52.     //for(int i=0; i<100; i++)
  53.        // cout<<result2[i]<<endl;
  54.  
  55.     for(int i=0; i<n; i++)
  56.     {
  57.         long long l,r,x,y;
  58.         cin>>l>>r;
  59.  
  60.         it1=upper_bound(result2.begin(),result2.end(),l);
  61.         it2=lower_bound(result2.begin(),result2.end(),l);
  62.         long long a=(it1 - result2.begin())+1;
  63.         long long b=(it2 - result2.begin())+1;
  64.         if(a != b)
  65.             x = b;
  66.         else x=a;
  67.         //cout<<x<<endl;
  68.  
  69.         it3=upper_bound(result2.begin(),result2.end(),r);
  70.         it4=lower_bound(result2.begin(),result2.end(),r);
  71.         long long c = (it3 - result2.begin())+1;
  72.         long long d = (it4 - result2.begin())+1;
  73.         if(c != d)
  74.             y=c;
  75.         else y=d;
  76.  
  77.         //cout<<y<<endl;
  78.         //divisor(r);
  79.  
  80.         int ans=y-x;
  81.         cout<<ans<<endl;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement