library

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

View the Project on GitHub matumoto1234/library

:warning: math/totient-table.hpp

Depends on

Code

#pragma once

#include "./base.hpp"

#include <vector>

namespace matumoto {
  vector<int> totient_table(int n) {
    vector<int> euler(n + 1);
    for (int i = 0; i <= n; i++) {
      euler[i] = i;
    }
    for (int i = 2; i <= n; i++) {
      if (euler[i] == i) {
        for (int j = i; j <= n; j += i) {
          euler[j] = euler[j] / i * (i - 1);
        }
      }
    }
    return euler;
  }
} // namespace matumoto
#line 2 "math/totient-table.hpp"

#line 2 "math/base.hpp"

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

#include <vector>

namespace matumoto {
  vector<int> totient_table(int n) {
    vector<int> euler(n + 1);
    for (int i = 0; i <= n; i++) {
      euler[i] = i;
    }
    for (int i = 2; i <= n; i++) {
      if (euler[i] == i) {
        for (int j = i; j <= n; j += i) {
          euler[j] = euler[j] / i * (i - 1);
        }
      }
    }
    return euler;
  }
} // namespace matumoto
Back to top page