关于欧拉函数的讲解:
题目:
代码实现:
#include <iostream>
using namespace std;
int main()
{
int n = 0;
scanf("%d", &n);
while (n --)
{
int x = 0;
scanf("%d", &x);
int ans = x;
for(int i = 2; i <= x / i; i++)
{
if(x % i == 0)
{
ans = (ans / i) * (i - 1); //把i除到(i - 1)里面, 就得到(1 - 1/i), 那实际上就相当于ans/(1 - 1/i);
//但是不能写成这样,ans = ans / (1 - 1 / i);因为i >= 2,这样没有办法计算分数,会忽略掉1 / i,造成结果不准确
while(x % i == 0) x /= i;
}
}
if(x > 1) ans = (ans / x) * (x - 1);
cout << ans << endl;
}
return 0;
}