Question meaning: ask Q times, each time ask how many x in [L, R] satisfy x=a^p (a>0,p>1)
Q<=1e5. 1<=L<=R<= 1e18.
The upper bound is 1e18, then p will not exceed 61 at most .
Now calculate how many x of f[1,n] satisfy x=a^p. Then the answer is f[r]-f[l-1
] Take p, what is the maximum a of a^p<=n at this time, and then find that repeated processing can't come....wa...
You can violently preprocess all Perfect Numbers within 1e18, p>=3. O(1e6).
Q<=1e5. 1<=L<=R<= 1e18.
The upper bound is 1e18, then p will not exceed 61 at most .
Now calculate how many x of f[1,n] satisfy x=a^p. Then the answer is f[r]-f[l-1
] Take p, what is the maximum a of a^p<=n at this time, and then find that repeated processing can't come....wa...
You can violently preprocess all Perfect Numbers within 1e18, p>=3. O(1e6).
Then for a given n, there are sqrt(n) of p==2. Then when p>=3, the last <=n position in the bisection in the vector can be used.
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; vector<ll> v; void init() { ll n=1e18; for(ll i=2;i*i*i<=n;i++) //when p>=3 enumerate a { ll s=i*i; while(s<=n/i) { s*=i; ll t=sqrt(s); if(t*t!=s) // v.push_back(s); } } sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); } ll calc(ll n) { ll idx=lower_bound(v.begin(),v.end(),n)-v.begin(); if(idx<v.size()&&v[idx]>n) idx--; if(idx==v.size()) idx--; //cout<<n<<' '<<sqrt(n)<<' '<<idx<<'\n'; return ll(sqrt(n))+idx; } intmain() { ios::sync_with_stdio(false); cin.tie(0); init(); ll Q,l,r; cin>>Q; while(Q--) { cin>>l>>r; cout<<calc(r)-calc(l-1)<<'\n'; } return 0; }