Robot HYSBZ - 1408(欧拉函数)

Robot HYSBZ - 1408(欧拉函数)

题目大意

给出一个已经奇偶分解的数,问其奇数个不同奇素数组成的因数的欧拉函数之和,与偶数个奇素数组成的因数的欧拉函数之和,与剩下的因数的欧拉函数之和分别为多少

解题思路

奇数个不同奇素数组成的因数的欧拉函数之和设为ans0,偶数个奇素数组成的因数的欧拉函数之和设为ans1,据欧拉函数积性函数的性质可以得出递推式
a n s 0 = a n s 0 + a n s 1 ( p 1 ) a n s 1 = a n s 1 + ( a n s 0 + 1 ) ( p 1 ) ans0=ans0+ans1*(p-1)\\ ans1=ans1+(ans0+1)*(p-1)
而欧拉函数又有性质 m = d n ϕ ( d ) m=\sum_{d\mid n}\phi(d)

而一不为任何数的老师,因此剩下的因数即为 m a n s 0 a n s 1 1 m-ans0-ans1-1

AC代码

#include<bits/stdc++.h>
using namespace std;
const int mod=10000;
int quick_pow(int a,int b)
{
	a=a%mod;
	int ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	int k;
	scanf("%d",&k);
	int M=1;
	int p,e;
	int ans0=0,ans1=0;
	while(k--)
	{
		scanf("%d%d",&p,&e);
		M=M*quick_pow(p,e)%mod;
		if(p==2) continue;
		int temp0=(ans0+ans1*(p-1)%mod)%mod;
		int temp1=((ans0+1)*(p-1)%mod+ans1)%mod;
		ans0=temp0;ans1=temp1;
	}
	printf("%d\n%d\n%d\n",ans0,ans1,((M-1-ans0-ans1)%mod+mod)%mod);
}

猜你喜欢

转载自blog.csdn.net/baiyifeifei/article/details/87908648