plduhoux
2/21/2018 - 9:25 PM

eulersTotientFunction

int eulersTotientFunction(int n) {
    int nb = 1;
    for (int i = 2; i < n; i++) {
        if (coprime(i, n)) nb++;
    }
    return nb;
}

boolean coprime(int a, int b) {
    for (int i = 2; i <= Math.min(a,b); i++) {
        if (a % i == 0 && b % i == 0) return false;
    }
    return true;
}