CodeForces1036 F Relatively Prime Powers (Mobius inclusion and exclusion)
Meaning of the questions:
For a number
, which may be expressed as
Now, if a number
good number which satisfies
, 2 to ask you how many n is the number of good number.
answer:
For this problem, we can soon expect the inclusion-exclusion theorem, as long as the conditions are not satisfied n-1 minus the number Jiuhaola. Does not satisfy the condition that all of the number of times and less than or equal to a number greater than 2. It is not obvious what the derivation of Mobius function, it is easy to know that after this matter (but pay attention to the accuracy of control on the root).
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
bool isprime[maxn];
int prime[maxn];
int mu[maxn];
void Mu()
{
memset(isprime,1,sizeof(isprime));
mu[1]=1;
int temp=0;
for(int i=2;i<maxn;i++)
{
if(isprime[i]) prime[++temp]=i,mu[i]=-1;
for(int j=1;j<=temp&&prime[j]*i<maxn;j++)
{
isprime[i*prime[j]]=0;
if(i%prime[j]==0)
{
mu[i*prime[j]]=0;
break;
}
else mu[i*prime[j]]=-mu[i];
}
}
}
int a[maxn];
long long gen(long long n,long long k){
long long t=powl(n,1./k)-0.5;
return t+(powl(t+1,k)-0.5<=n);
}
int main()
{
#ifdef TEST
freopen("input.txt","r",stdin);
#endif
int T,m,i,j,k;
long long n;
Mu();
scanf("%d",&T);
long long ans,temp;
while(T--)
{
scanf("%lld",&n);
ans=n-1;
for(i=2;i<60;i++)
{
ans+=mu[i]*(gen(n,i)-1);
}
cout<<ans<<endl;
}
}