library

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

View the Project on GitHub matumoto1234/library

:warning: math/totient.hpp

Depends on

Code

#pragma once

#include "./base.hpp"

namespace matumoto {
  constexpr ll totient(ll n) {
    ll res = n;
    for (ll 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;
  }
} // namespace matumoto
#line 2 "math/totient.hpp"

#line 2 "math/base.hpp"

namespace matumoto {
  using namespace std;
  using ll = long long;
} // namespace matumoto
#line 4 "math/totient.hpp"

namespace matumoto {
  constexpr ll totient(ll n) {
    ll res = n;
    for (ll 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;
  }
} // namespace matumoto
Back to top page