Luogu P5277 题解
\(\texttt{Description}\)
给 \(\deg = n-1\) 的多项式 \(f\),求多项式 \(g\) 满足
$$
g \equiv \sqrt f \pmod {x^n}
$$
\(\texttt{Solution}\)
考虑牛顿迭代:有 \(h(g(x)) = g(x)^2 - f(x) \equiv 0 \pmod {x^n}\)
$$
g(x) \equiv \dfrac {g_0(x) - g_0^2(x) - f(x)} {2g_0(x)} \pmod {x^n}
$$
$$
g(x) \equiv \dfrac {g_0^2(x)+f(x)} {2g_0(x)} \pmod {x^n}
$$
其中 \(g_0(x)\) 是在模 \(x^{ \lceil \dfrac {n} 2 \rceil}\) 时的答案。
在 \(n=1\) 时用 cipolla 算一下就可以了。
\(\texttt{Code}\)
inline auto Sqrt(vector<int> a) {
if (a.size() == 1) return vector<int> (1,quad::cipolla(a[0])) ;
const int len = a.size() ;
auto ta = a;
ta.resize((len + 1) >> 1) ;
auto tb = Sqrt(ta);
tb.resize(len) ;
auto tc = tb * tb;
tc.resize(len) ;
for (auto &it : tb) it = 2ll * it % mod ;
for (int i = 0; i < len; ++i) tc[i] = (tc[i] + a[i]) % mod ;
return tc = tc * Inv(tb),tc.resize(len),tc ;
}

浙公网安备 33010602011771号