#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int a;
cin >> a;
int ret = a;
for (int i = 2; i <= a / i; i++) {
if (a % i == 0) {
ret -= ret / i;
while (a % i == 0) a /= i;
}
}
if (a > 1) ret -= ret / a;
cout << ret << endl;
}
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6 + 10;
int p[N] = { 0 };
vector<int> v, st(N);
int main() {
p[1] = 1;
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
if (!st[i]) {
v.push_back(i);
p[i] = i - 1;
}
for (int j = 0; v[j] <= n / i; j++) {
st[v[j] * i] = 1;
if (i % v[j] == 0) {
p[v[j] * i] = v[j] * p[i];
break;
}
p[v[j] * i] = p[i] * (v[j] - 1);
}
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += p[i];
}
cout << ans;
return 0;
}
欧拉定理: