Title effect: A total of seeking the number from 1 to N can be expressed as the number \ (M ^ K, K \ gt 1 \) . \ (N \ le 1e18 \)
Solution:
find a large N, if the direct enumeration of M, then there is the amount of data 1e9 level, certainly expires, so consider a power of enumeration. It found that for a power of the number of matches are N k take apart the whole K-th power, while noting that k ranges from a maximum of 60, since 60 is 2 1e18 power level. So consider small to large power times to enumerate, but found that some numbers will have repeated, such as: \ ((2 ^ 3) ^ 2 = (2 ^ 2) ^ 3 = 2 ^ 6 \) , namely: the same a digital contribution is counted three times, and therefore relates to the inclusion and exclusion, namely: when the power of prime factorization of an odd number of cumulative contribution, whereas the contribution is subtracted, so only need to be prime numbers 1-60 inclusion and exclusion can operate, namely: the problem is converted combination has become an issue of multiple sets.
code show as below
#include <bits/stdc++.h>
using namespace std;
const int maxn=61;
typedef long long LL;
LL n;
int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
void solve(){
LL ans=0;
int ub=0;
while((1LL<<prime[ub+1])<=n)++ub;
for(int i=1;i<1<<ub;i++){
LL ret=1;
int cnt=0;
for(int j=0;j<ub;j++)
if(i>>j&1){
++cnt,ret*=prime[j];
}
if(cnt&1)ans+=(LL)(pow(n,1.0/ret)+1e-8);
else ans-=(LL)(pow(n,1.0/ret)+1e-8);
}
printf("%lld\n",ans+1);
}
int main(){
while(scanf("%lld",&n)!=EOF){
solve();
}
return 0;
}