algorithm

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

View the Project on GitHub gtnao/algorithm

:heavy_check_mark: src/math/euler_phi_table.hpp

Verified with

Code

#pragma once

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

template <typename T = int> vector<T> euler_phi_table(T n) {
  vector<T> res(n + 1);
  for (T i = 0; i <= n; ++i) {
    res[i] = i;
  }
  for (T i = 2; i <= n; ++i) {
    if (res[i] == i) {
      for (T j = i; j <= n; j += i) {
        res[j] -= res[j] / i;
      }
    }
  }
  return res;
}
#line 2 "src/math/euler_phi_table.hpp"

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

template <typename T = int> vector<T> euler_phi_table(T n) {
  vector<T> res(n + 1);
  for (T i = 0; i <= n; ++i) {
    res[i] = i;
  }
  for (T i = 2; i <= n; ++i) {
    if (res[i] == i) {
      for (T j = i; j <= n; j += i) {
        res[j] -= res[j] / i;
      }
    }
  }
  return res;
}
Back to top page