kyopro-lib

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

View on GitHub

:x: Euler's totient function (Table)
(Mylib/Number/Totient/totient_table.cpp)

Operations

Requirements

Notes

Problems

References

Required by

Verified with

Code

#pragma once
#include <numeric>
#include <vector>

namespace haar_lib {
  std::vector<int> totient_table(int n) {
    std::vector<int> ret(n + 1);
    std::iota(ret.begin(), ret.end(), 0);

    for (int i = 2; i <= n; ++i) {
      if (ret[i] == i) {
        for (int j = i; j <= n; j += i) {
          ret[j] = ret[j] / i * (i - 1);
        }
      }
    }

    return ret;
  }
}  // namespace haar_lib
#line 2 "Mylib/Number/Totient/totient_table.cpp"
#include <numeric>
#include <vector>

namespace haar_lib {
  std::vector<int> totient_table(int n) {
    std::vector<int> ret(n + 1);
    std::iota(ret.begin(), ret.end(), 0);

    for (int i = 2; i <= n; ++i) {
      if (ret[i] == i) {
        for (int j = i; j <= n; j += i) {
          ret[j] = ret[j] / i * (i - 1);
        }
      }
    }

    return ret;
  }
}  // namespace haar_lib
Back to top page