多项式牛顿迭代
尝试不带 FFT/NTT 讲解,似乎真的能讲?
对于给定的
对
注意到
因此
更具体的,可以写做
多项式 inv
不妨设
cpp
Poly inv(int m) const {
Poly x = {qpow(T[0])};
for (int t = 2; t < m * 2; t *= 2) {
x = x * 2 - (x * x) * cut(t);
x.redeg(t);
}
return x.redeg(m);
}
Poly div(int m, const Poly& g) const {
if (deg() == 0)
return {};
return (cut(m) * g.inv(m)).redeg(m);
}
Poly inv(int m) const {
Poly x = {qpow(T[0])};
for (int t = 2; t < m * 2; t *= 2) {
x = x * 2 - (x * x) * cut(t);
x.redeg(t);
}
return x.redeg(m);
}
Poly div(int m, const Poly& g) const {
if (deg() == 0)
return {};
return (cut(m) * g.inv(m)).redeg(m);
}
多项式 ln
依据
有
cpp
Poly ln(int m) const {
return deriv().div(m - 1, cut(m)).integr();
}
Poly ln(int m) const {
return deriv().div(m - 1, cut(m)).integr();
}
多项式 exp
令
cpp
Poly exp(int m) const {
Poly x = {1};
for (int t = 2; t < m * 2; t *= 2) {
x = x * (Poly{1} - x.ln(t) + cut(t));
x.redeg(t);
}
return x.redeg(m);
}
Poly exp(int m) const {
Poly x = {1};
for (int t = 2; t < m * 2; t *= 2) {
x = x * (Poly{1} - x.ln(t) + cut(t));
x.redeg(t);
}
return x.redeg(m);
}
多项式 sqrt
令
cpp
Poly sqrt(int m) const {
Poly x = {1};
for (int t = 2; t < m * 2; t *= 2) {
x = (x + cut(t).div(t, x)) * qpow(2);
}
return x.redeg(m);
}
Poly sqrt(int m) const {
Poly x = {1};
for (int t = 2; t < m * 2; t *= 2) {
x = (x + cut(t).div(t, x)) * qpow(2);
}
return x.redeg(m);
}
提示
以上代码真的能跑,时间复杂度
还有一些循环卷积优化和分块的常数优化,感兴趣的可以阅读。