fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int tc;
  6. ll x,y;
  7. vector<ll>vec;
  8. ll calc(int x)
  9. {
  10. int pos=upper_bound(vec.begin(),vec.end(),x)-vec.begin();
  11. return pos;
  12. }
  13. int main()
  14. {
  15. ios_base::sync_with_stdio(0);
  16. cin.tie(0);cout.tie(0);
  17. freopen("puteri.inp","r",stdin);
  18. // freopen("puteri.out","w",stdout);
  19. for(ll i=2;i<=1000000;i++)
  20. {
  21. ll cur=i*i;
  22. int d=2;
  23. while(cur<=1e18/i)
  24. {
  25. cur=cur*i;
  26. d++;
  27. if(d%2==1)vec.push_back(cur);
  28. }
  29. }
  30. sort(vec.begin(),vec.end());
  31. vec.erase(unique(vec.begin(),vec.end()),vec.end());
  32. cin>>tc;
  33. while(tc--)
  34. {
  35. cin>>x>>y;
  36. ll u=calc(y)-calc(x-1);
  37. y=sqrt(y);
  38. ll t=sqrt(x);
  39. if(t*t!=x)t++;
  40. cout<<u+y-t+1<<'\n';
  41. }
  42. return 0;
  43. }
  44.  
  45.  
Success #stdin #stdout 0.09s 12796KB
stdin
Standard input is empty
stdout
Standard output is empty