xxxxxxxxxx
void phi_1_to_n(int n) {
vector<int> phi(n + 1);
for (int i = 0; i <= n; i++)
phi[i] = i;
for (int i = 2; i <= n; i++) {
if (phi[i] == i) {
for (int j = i; j <= n; j += i)
phi[j] -= phi[j] / i;
}
}
}
xxxxxxxxxx
import math
def euler_totient(n: int) -> int:
"""returns number of ints from 1 to n-1 that are coprime with n
"""
a = {x for x in range(1, n - 1) if math.gcd(x, n) == 1}
return len(a)