algo — C++23 日本語リファレンス GitHub

inv_of_polynomials

関数 · 形式的冪級数 (FPS)

template <internal::static_modint_c mint>
std::optional<std::vector<mint>> inv_of_polynomials(const std::vector<mint> &f, const std::vector<mint> &g);

概要

多項式の逆元 (modular inverse of polynomials)

$f(x) h(x) \equiv 1 \pmod{g(x)}$ かつ $\deg h < \deg g$ を満たす $h$ を Half-GCD による拡張 Euclid 互除法で求める。 逆元が存在する($\gcd(f, g)$ が定数)ときのみ値を返し、存在しなければ std::nullopt を返す。 返り値は末尾 $0$ を除いた正規形(逆元が $0$ 多項式のときは空列)。

テンプレートパラメータ

名前 説明
mint static modint

パラメータ

名前 説明
f 係数列(最高次係数 != 0)
g 法多項式の係数列(最高次係数 != 0)

戻り値

std::optional<std::vector<mint>> 逆元 $h$($\deg h < \deg g$)。逆元が無ければ std::nullopt

計算量

関連項目