cp-documentation

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

View the Project on GitHub zawa-tin/cp-documentation

:heavy_check_mark: Src/FPS/DivisionOfPolynomials.hpp

Depends on

Verified with

Code

#pragma once

#include "FPSNTTFriendly.hpp"

#include <algorithm>
#include <ranges>
#include <utility>

namespace zawa {

// f = gq + r
// first... q
// second... r
template <usize MOD = 998244353>
std::pair<FPSNTTFriendly<MOD>, FPSNTTFriendly<MOD>> DivisionOfPolynomials(FPSNTTFriendly<MOD> f, FPSNTTFriendly<MOD> g) {
    while (g.size() and g.back() == 0)
        g.pop_back();
    while (f.size() and f.back() == 0)
        f.pop_back();
    assert(g.size());
    const usize n = f.size(), m = g.size();
    if (n == 0 or n < m)
        return {FPSNTTFriendly<MOD>{}, f};
    std::ranges::reverse(f);
    std::ranges::reverse(g);
    auto q = f * g.inv(n);
    if (q.size() > n - m + 1)
        q.resize(n - m + 1);
    std::ranges::reverse(f);
    std::ranges::reverse(g);
    std::ranges::reverse(q);
    auto r = f - g * q;
    while (r.size() and r.back() == 0)
        r.pop_back();
    return {q, r};
}

} // namespace zawa
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 260, in _resolve
    raise BundleErrorAt(path, -1, "no such header")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: atcoder/modint: line -1: no such header
Back to top page