library

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

View the Project on GitHub kk2a/library

:heavy_check_mark: math_mod/mod_sqrt.hpp

Depends on

Required by

Verified with

Code

#ifndef KK2_MATH_MOD_MOD_SQRT_HPP
#define KK2_MATH_MOD_MOD_SQRT_HPP 1

#include <cassert>

#include "../modint/mont_arb.hpp"

namespace kk2 {

template <class T, class U> long long mod_sqrt(const T &a, const U &p) {
    assert(0 <= a && a < p);
    if (a < 2) return a;
    using Mint = ArbitraryLazyMontgomeryModInt<54105064>;
    Mint::setmod(p);
    if (Mint(a).pow((p - 1) >> 1) != Mint(1)) return -1;
    Mint b = 1;
    while (b.pow((p - 1) >> 1) == Mint(1)) b += 1;
    long long m = p - 1, e = 0;
    while (m % 2 == 0) m >>= 1, e++;
    Mint x = Mint(a).pow((m - 1) >> 1);
    Mint y = Mint(a) * x * x;
    x *= a;
    Mint z = Mint(b).pow(m);
    while (y != Mint(1)) {
        long long j = 0;
        Mint t = y;
        while (t != Mint(1)) {
            j++;
            t *= t;
        }
        z = z.pow(1LL << (e - j - 1));
        x *= z;
        z *= z;
        y *= z;
        e = j;
    }
    return x.val();
}

} // namespace kk2

#endif // KK2_MATH_MOD_MOD_SQRT_HPP
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/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.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.0/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.0/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.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 312, in update
    raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: type_traits/integral.hpp: line 4: #pragma once found in a non-first line
Back to top page