φ函数的值,通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。
#include<iostream>
#include<cmath>
using namespace std;
int Get(int n)
{
int res,i;
if(n==0)
return 0;
else
{
res=n;
for(i=2;n!=1;i++)
{
if(n%i==0)
{
res*=(i-1);
res/=i;
}
while(n%i==0) n/=i;
}
return res;
}
}
int main()
{
int CN,N;
cin>>CN;
while(CN--)
{
cin>>N;
cout<<Get(N)<<endl;
}
return 0;
}原文地址:http://blog.csdn.net/a809146548/article/details/45175369