Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

phi function (n log (log(n)))

int phi(int n) {
    int result = n;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
Source by cp-algorithms.com #
 
PREVIOUS NEXT
Tagged: #phi #function #log
ADD COMMENT
Topic
Name
6+5 =