CodeForces1036 F Relatively Prime Powers (Mobius inclusion and exclusion)

CodeForces1036 F Relatively Prime Powers (Mobius inclusion and exclusion)

Portal

Meaning of the questions:

For a number x x , which may be expressed as x = 2 e 1 3 e 2 5 e 3 . . . . x = 2 ^ {e_1} ^ {* 3 * 5 E_2} ^ {} E_3 ....
Now, if a number a a good number which satisfies g c d ( e 1 , e 2 , . . . . ) = 1 gcd (e_1, E_2, ....) = 1 , 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;
	 } 
}
Published 51 original articles · won praise 6 · views 6327

Guess you like

Origin blog.csdn.net/weixin_40859716/article/details/82823723