cpp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub 9tc/cpp-library

:heavy_check_mark: math/eulers-phi-function.hpp

Verified with

Code

template <typename T>
T eulersPhiFunction(T n){
    T res = n;
    for(T i = 2; i * i <= n; ++i){
        if(n % i == 0){
            res -= res / i;
            while(n % i == 0) n /= i;
        }
    }

    if(n > 1) res -= res / n;
    return res;
}
#line 1 "math/eulers-phi-function.hpp"
template <typename T>
T eulersPhiFunction(T n){
    T res = n;
    for(T i = 2; i * i <= n; ++i){
        if(n % i == 0){
            res -= res / i;
            while(n % i == 0) n /= i;
        }
    }

    if(n > 1) res -= res / n;
    return res;
}
Back to top page