algorithm

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

View the Project on GitHub gtnao/algorithm

:heavy_check_mark: test/aoj/ntl_1_d.test.cpp

Depends on

Code

#define PROBLEM                                                                \
  "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_D"

#include <bits/stdc++.h>
using namespace std;

#include "../../src/math/euler_phi.hpp"

int main() {
  long long n;
  cin >> n;
  cout << euler_phi(n) << endl;
  return 0;
}
#line 1 "test/aoj/ntl_1_d.test.cpp"
#define PROBLEM                                                                \
  "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_D"

#include <bits/stdc++.h>
using namespace std;

#line 2 "src/math/euler_phi.hpp"

#line 4 "src/math/euler_phi.hpp"
using namespace std;

#line 2 "src/math/prime_factor.hpp"

#line 4 "src/math/prime_factor.hpp"
using namespace std;

template <typename T = long long> map<T, T> prime_factor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) {
    res[n] = 1;
  }
  return res;
}
#line 7 "src/math/euler_phi.hpp"

template <typename T = long long> T euler_phi(T n) {
  T res = n;
  for (auto &p : prime_factor(n)) {
    res -= res / p.first;
  }
  return res;
}
#line 8 "test/aoj/ntl_1_d.test.cpp"

int main() {
  long long n;
  cin >> n;
  cout << euler_phi(n) << endl;
  return 0;
}
Back to top page