2 25608 24027
7680 16016
#include <iostream>
using namespace std;
int Euler(int x)// 求 欧拉函数值 其实就是通式的应用
{
int i,res = x;
for(i = 2;i*i<=x;i++) //
{
if(x%i==0)
res = res/i*(i-1);
while(x%i==0) //保证遍历的一定是质因子
x/=i;
}
if(x>1)
res = res / x*(x-1);// x 若为1,则所有质因子全部遍历,不为1 则表示最后一个质因子残余,继续res / x*(x-1)
return res;
}
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
cout<<Euler(n)<<endl;
}
return 0;
}
hdu 1286 找新朋友 (欧拉函数),布布扣,bubuko.com
原文:http://blog.csdn.net/gray_1566/article/details/24491811