kyopro-lib

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

View on GitHub

:x: test/aoj/NTL_1_D/main.totient.test.cpp

Depends on

Code

#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D"

#include <iostream>
#include "Mylib/Number/Totient/totient.cpp"

namespace hl = haar_lib;

int main() {
  int n;
  std::cin >> n;

  std::cout << hl::totient(n) << std::endl;

  return 0;
}
#line 1 "test/aoj/NTL_1_D/main.totient.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D"

#include <iostream>
#line 2 "Mylib/Number/Totient/totient.cpp"
#include <cstdint>

namespace haar_lib {
  constexpr int64_t totient(int64_t n) {
    int64_t ret = n;

    for (int64_t i = 2; i * i <= n; ++i) {
      if (n % i == 0) {
        ret -= ret / i;
        while (n % i == 0) n /= i;
      }
    }

    if (n != 1) ret -= ret / n;

    return ret;
  }
}  // namespace haar_lib
#line 5 "test/aoj/NTL_1_D/main.totient.test.cpp"

namespace hl = haar_lib;

int main() {
  int n;
  std::cin >> n;

  std::cout << hl::totient(n) << std::endl;

  return 0;
}
Back to top page