题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1286
题解:
此题需要使用欧拉函数,欧拉函数是计算小于M的所有正整数中所有与M互质的数
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int euler(int x)
{
int i, res=x;
for (i = 2; i < (int)sqrt(x * 1.0) + 1; i++)
if(x%i==0)
{
res = res / i * (i - 1);
while (x % i == 0)
x /= i;
}
if (x > 1)
res = res / x * (x - 1);
return res;
}
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
cout << euler(n) <<endl;
}
return 0;
}