POJ2407 Relatives
http://poj.org/problem?id=2407
题意:求一个大数的欧拉函数
欧拉函数
运用公式即可
\[\varphi(n)=(1-\frac{1}{p_{1}}) (1-\frac{1}{p_{2}})\cdots(1-\frac{1}{p_{m}})n \qquad(p_{i}为n的质因数)
\]
\(C++ Code:\)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long n;
int main()
{
for (;;)
{
scanf("%lld",&n);
if (!n)
break;
if (n==1)
{
puts("0");
continue;
}
long long g=n;
long long ans=n;
for (long long i=2;i*i<=g;i++)
if (g%i==0)
{
ans=ans-ans/i;
while (g%i==0)
g/=i;
}
if (g^1)
ans=ans-ans/g;
cout << ans << endl;
}
return 0;
}