kyopro-lib

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

View on GitHub

:warning: Enumerate mod inv
(Mylib/Number/Mod/enumerate_mod_inv.cpp)

Operations

Requirements

Notes

Problems

References

Code

#pragma once
#include <cstdint>
#include <vector>

namespace haar_lib {
  std::vector<int64_t> enumerate_mod_inv(int n, int64_t p) {
    std::vector<int64_t> ret(n + 1);

    ret[1] = 1;

    for (int i = 2; i <= n; ++i) {
      ret[i] = (p / i) * (p - ret[p % i]) % p;
    }

    return ret;
  }
}  // namespace haar_lib
#line 2 "Mylib/Number/Mod/enumerate_mod_inv.cpp"
#include <cstdint>
#include <vector>

namespace haar_lib {
  std::vector<int64_t> enumerate_mod_inv(int n, int64_t p) {
    std::vector<int64_t> ret(n + 1);

    ret[1] = 1;

    for (int i = 2; i <= n; ++i) {
      ret[i] = (p / i) * (p - ret[p % i]) % p;
    }

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