给定多项式
G
(
x
)
G(x)
G(x),已知
A
(
x
)
A(x)
A(x)满足
G
(
A
(
x
)
)
≡
0
m
o
d
x
n
G(A(x))\equiv 0\;mod\;x^n
G(A(x))≡0modxn
求模
x
n
x^n
xn意义下的
A
(
x
)
A(x)
A(x)
倍增法
首先解出
[
x
0
]
G
(
A
(
x
)
)
≡
0
m
o
d
x
\begin{aligned} [x^0]G(A(x))\equiv 0\;mod\;x \end{aligned}
[x0]G(A(x))≡0modx
因为是在模
x
x
x意义下解方程,所以
A
(
x
)
A(x)
A(x)求出来也是在模
x
x
x意义下,所以
A
(
x
)
A(x)
A(x)是常数。
假设求出了模
x
⌈
n
2
⌉
x^{\lceil\frac{n}{2}\rceil}
x⌈2n⌉意义下的解
A
′
(
x
)
A^{'}(x)
A′(x),要求模
x
n
x^n
xn意义下的解
A
(
x
)
A(x)
A(x)
因为
G
(
A
(
x
)
)
≡
0
m
o
d
x
n
G(A(x))\equiv0\;mod\;x^n
G(A(x))≡0modxn和
x
⌈
n
2
⌉
∣
x
n
x^{\lceil\frac{n}{2}\rceil}|x^n
x⌈2n⌉∣xn,则
{
G
(
A
(
x
)
)
≡
0
m
o
d
x
⌈
n
2
⌉
G
(
A
′
(
x
)
)
≡
0
m
o
d
x
⌈
n
2
⌉
→
A
(
x
)
≡
A
′
(
x
)
m
o
d
x
⌈
n
2
⌉
\begin{cases} G(A(x))&\equiv0\;mod\;x^{\lceil\frac{n}{2}\rceil}\\ G(A^{'}(x))&\equiv0\;mod\;x^{\lceil\frac{n}{2}\rceil} \end{cases} \rightarrow A(x)\equiv A^{'}(x)\;mod\;x^{\lceil\frac{n}{2}\rceil}
{G(A(x))G(A′(x))≡0modx⌈2n⌉≡0modx⌈2n⌉→A(x)≡A′(x)modx⌈2n⌉
把
G
(
A
(
x
)
)
G(A(x))
G(A(x))在
A
′
(
x
)
A^{'}(x)
A′(x)处泰勒展开,得
G
(
A
(
x
)
)
=
∑
i
=
0
∞
G
(
i
)
(
A
′
(
x
)
)
i
!
[
A
(
x
)
−
A
′
(
x
)
]
i
G(A(x))=\sum_{i=0}^{\infty}\frac{G^{(i)}(A^{'}(x))}{i!}\big[A(x)-A^{'}(x)\big]^i
G(A(x))=i=0∑∞i!G(i)(A′(x))[A(x)−A′(x)]i
因为
A
(
x
)
−
A
′
(
x
)
≡
0
m
o
d
x
⌈
n
2
⌉
A(x)-A^{'}(x)\equiv 0\;mod\;x^{\lceil\frac{n}{2}\rceil}
A(x)−A′(x)≡0modx⌈2n⌉,所以
[
A
(
x
)
−
A
′
(
x
)
]
i
≡
0
m
o
d
x
i
⌈
n
2
⌉
\big[A(x)-A^{'}(x)\big]^i\equiv0\;mod\;x^{i\lceil\frac{n}{2}\rceil}
[A(x)−A′(x)]i≡0modxi⌈2n⌉
当
i
≥
2
i\ge 2
i≥2时,
i
⌈
n
2
⌉
≥
n
i\lceil\frac{n}{2}\rceil\ge n
i⌈2n⌉≥n,所以
x
n
∣
x
i
⌈
n
2
⌉
x^n|x^{i\lceil\frac{n}{2}\rceil}
xn∣xi⌈2n⌉,所以
[
A
(
x
)
−
A
′
(
x
)
]
i
≡
0
m
o
d
x
n
\big[A(x)-A^{'}(x)\big]^i\equiv0\;mod\;x^{n}
[A(x)−A′(x)]i≡0modxn。所以泰勒展开在模
x
n
x^n
xn得意义下只保留前两项。
G
(
A
(
x
)
)
≡
G
(
A
′
(
x
)
)
+
G
(
1
)
(
A
′
(
x
)
)
[
A
(
x
)
−
A
′
(
x
)
]
m
o
d
x
n
0
≡
G
(
A
′
(
x
)
)
+
G
(
1
)
(
A
′
(
x
)
)
[
A
(
x
)
−
A
′
(
x
)
]
m
o
d
x
n
A
(
x
)
≡
A
′
(
x
)
−
G
(
A
′
(
x
)
)
G
(
1
)
(
A
′
(
x
)
)
m
o
d
x
n
\begin{aligned} G(A(x))&\equiv G(A^{'}(x))+G^{(1)}(A^{'}(x))\big[A(x)-A^{'}(x)\big]\;mod\;x^n\\ 0&\equiv G(A^{'}(x))+G^{(1)}(A^{'}(x))\big[A(x)-A^{'}(x)\big]\;mod\;x^n\\ A(x)&\equiv A^{'}(x)-\frac{G(A^{'}(x))}{G^{(1)}(A^{'}(x))}\;mod\; x^n \end{aligned}
G(A(x))0A(x)≡G(A′(x))+G(1)(A′(x))[A(x)−A′(x)]modxn≡G(A′(x))+G(1)(A′(x))[A(x)−A′(x)]modxn≡A′(x)−G(1)(A′(x))G(A′(x))modxn
应用:
- 多项式求逆元
给定多项式 A ( x ) A(x) A(x),求 B ( x ) B(x) B(x)满足 A ( x ) B ( x ) ≡ 1 m o d x n A(x)B(x)\equiv1\;mod\;x^n A(x)B(x)≡1modxn。
A ( x ) B ( x ) ≡ 1 m o d x n A ( x ) − 1 B ( x ) ≡ 0 m o d x n \begin{aligned} A(x)B(x)&\equiv1\;mod\;x^n\\ A(x)-\frac{1}{B(x)}&\equiv 0\;mod\;x^n\\ \end{aligned} A(x)B(x)A(x)−B(x)1≡1modxn≡0modxn
首先把 A ( x ) − 1 B ( x ) A(x)-\frac{1}{B(x)} A(x)−B(x)1看成关于 B ( x ) B(x) B(x)的函数,则设 G ( B ( x ) ) = A ( x ) − 1 B ( x ) G(B(x))=A(x)-\frac{1}{B(x)} G(B(x))=A(x)−B(x)1,所以 G ( B ( x ) ) ≡ 0 m o d x n G(B(x))\equiv 0\;mod\;x^n G(B(x))≡0modxn。和上面的形式一样,所以就有。
B ( x ) ≡ B ′ ( x ) − G ( B ′ ( x ) ) G ( 1 ) ( B ′ ( x ) ) m o d x n ≡ B ′ ( x ) − A ( x ) − 1 B ′ ( x ) 1 B ′ ( x ) 2 m o d x n ≡ B ′ ( x ) − A ( x ) B ′ ( x ) 2 + B ′ ( x ) m o d x n ≡ 2 B ′ ( x ) − A ( x ) B ′ ( x ) 2 m o d x n \begin{aligned} B(x)&\equiv B^{'}(x)-\frac{G(B^{'}(x))}{G^{(1)}(B^{'}(x))}\;mod\; x^n\\ &\equiv B^{'}(x)-\frac{A(x)-\frac{1}{B^{'}(x)}}{\frac{1}{B^{'}(x)^2}}\;mod\;x^n\\ &\equiv B^{'}(x)-A(x)B^{'}(x)^2+B^{'}(x)\;mod\;x^n\\ &\equiv 2B^{'}(x)-A(x)B^{'}(x)^2\;mod\;x^n\\ \end{aligned} B(x)≡B′(x)−G(1)(B′(x))G(B′(x))modxn≡B′(x)−B′(x)21A(x)−B′(x)1modxn≡B′(x)−A(x)B′(x)2+B′(x)modxn≡2B′(x)−A(x)B′(x)2modxn
这样就可以用倍增计算 - 多项式开方
给定多项式 A ( x ) A(x) A(x),求 B ( x ) B(x) B(x)满足 A ( x ) ≡ B ( x ) 2 m o d x n A(x)\equiv B(x)^2\;mod\;x^n A(x)≡B(x)2modxn。
设 G ( B ( x ) ) = A ( x ) − B ( x ) 2 G(B(x))=A(x)-B(x)^2 G(B(x))=A(x)−B(x)2,则
B ( x ) ≡ B ′ ( x ) − G ( B ′ ( x ) ) G ( 1 ) ( B ′ ( x ) ) m o d x n ≡ B ′ ( x ) − A ( x ) − B ′ ( x ) 2 − 2 B ′ ( x ) m o d x n ≡ B ′ ( x ) 2 + A ( x ) 2 B ′ ( x ) m o d x n \begin{aligned} B(x)&\equiv B^{'}(x)-\frac{G(B^{'}(x))}{G^{(1)}(B^{'}(x))}\;mod\; x^n\\ &\equiv B^{'}(x)-\frac{A(x)-B^{'}(x)^2}{-2B^{'}(x)}\;mod\;x^n\\ &\equiv \frac{B^{'}(x)}{2}+\frac{A(x)}{2B^{'}(x)}\;mod\;x^n \end{aligned} B(x)≡B′(x)−G(1)(B′(x))G(B′(x))modxn≡B′(x)−−2B′(x)A(x)−B′(x)2modxn≡2B′(x)+2B′(x)A(x)modxn - 多项式EXP
给定多项式 A ( x ) A(x) A(x),求 B ( x ) B(x) B(x)满足 e A ( x ) ≡ B ( x ) m o d x n e^{A(x)}\equiv B(x)\;mod\;x^n eA(x)≡B(x)modxn。
注意 e A ( x ) e^{A(x)} eA(x)存在必须满足 [ x 0 ] A ( x ) = 0 [x^0]A(x)=0 [x0]A(x)=0
两边取对数,设 G ( B ( x ) ) = A ( x ) − ln B ( x ) G(B(x))=A(x)-\ln{B(x)} G(B(x))=A(x)−lnB(x),则
B ( x ) ≡ B ′ ( x ) − G ( B ′ ( x ) ) G ( 1 ) ( B ′ ( x ) ) m o d x n ≡ B ′ ( x ) − A ( x ) − ln B ′ ( x ) − 1 B ′ ( x ) m o d x n ≡ B ′ ( x ) [ 1 − ln B ′ ( x ) + A ( x ) ] m o d x n \begin{aligned} B(x)&\equiv B^{'}(x)-\frac{G(B^{'}(x))}{G^{(1)}(B^{'}(x))}\;mod\; x^n\\ &\equiv B^{'}(x)-\frac{A(x)-\ln{B^{'}(x)}}{-\frac{1}{B^{'}(x)}}\;mod\;x^n\\ &\equiv B^{'}(x)[1-\ln{B^{'}(x)}+A(x)]\;mod\;x^n\\ \end{aligned} B(x)≡B′(x)−G(1)(B′(x))G(B′(x))modxn≡B′(x)−−B′(x)1A(x)−lnB′(x)modxn≡B′(x)[1−lnB′(x)+A(x)]modxn - 多项式的幂
计算 f k ( x ) m o d x n f^k(x)\ mod x^n fk(x) modxn
- 当 [ x 0 ] f ( x ) = 1 [x^0]f(x)=1 [x0]f(x)=1时, f k ( x ) ≡ exp ( k ln f ( x ) ) m o d x n f^k(x)\equiv \exp(k\ln{f(x)})\ mod x^n fk(x)≡exp(klnf(x)) modxn
- 当
[
x
0
]
f
(
x
)
≠
1
[x^0]f(x)\neq1
[x0]f(x)=1时,设
f
(
x
)
f(x)
f(x)的最低次项为
a
i
x
i
a_ix^i
aixi,则
f k ( x ) ≡ a i k x k i exp ( k ln f ( x ) a i x i ) m o d x n f^k(x)\equiv a_i^kx^{ki}\exp(k\ln{\dfrac{f(x)}{a_ix^i}})\ mod x^n fk(x)≡aikxkiexp(klnaixif(x)) modxn