summaryrefslogtreecommitdiff
path: root/math/phi.cpp
blob: c8f890042c65a7753fb6dc206368d57e26ceb8b5 (plain)
1
2
3
4
5
6
7
8
9
ll phi(ll n) {
  ll 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;
}