
题意:你懂得。
析:一看这个题应该是欧拉phi函数,也就说欧拉phi函数是指求从 1 到 n 中与 n 互素的数的个数,这个题很明显是这个意思嘛,不多说了。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn = 32768 + 5;
int phi[maxn+5]; void phi_table(int n){
memset(phi, 0, sizeof(phi));
phi[1] = 1;
for(int i = 2; i <= n; ++i) if(!phi[i])
for(int j = i; j <= n; j += i){
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i-1);
}
} int main(){
phi_table(maxn);
int n, T; cin >> T;
while(T--){
scanf("%d", &n);
printf("%d\n", phi[n]);
}
return 0;
}