跳到正文

个人记录

150粉福

Angelstar约 9 分钟
原文
文章信息与版本

文章信息

发布
2025年2月23日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 9 分钟

版本

  1. v1当前

150粉好久了,一直没弄福利。最近整了些多项式,不妨就这个吧。

PS:对多项式乘法不熟悉的同学,请自行学习。


多项式除法

给定 F(x),G(x)\mathrm F(x),\mathrm G(x),求 Q(x),R(x)\mathrm Q(x),\mathrm R(x) 满足

F(x)=Q(x)G(x)+R(x)\mathrm F(x)=\mathrm Q(x)\mathrm G(x)+\mathrm R(x),

degQ=degF−degG,degR<degG\mathrm{deg}_{\mathrm Q}=\mathrm{deg}_{\mathrm F}-\mathrm{deg}_{\mathrm G},\mathrm{deg}_{\mathrm R}<\mathrm{deg_{\mathrm G}}。

F(x−1)=Q(x−1)G(x−1)+R(x−1)\mathrm F(x^{-1})=\mathrm Q(x^{-1})\mathrm G(x^{-1})+\mathrm R(x^{-1})。

xnF(x−1)=xn−mQ(x−1)xmG(x−1)+xnR(x−1)x^n\mathrm F(x^{-1})=x^{n-m}\mathrm Q(x^{-1})x^m\mathrm G(x^{-1})+x^n\mathrm R(x^{-1})。

FR(x)=QR(x)GR(x)+xn−m+1RR(x)\mathrm F^\R(x)=\mathrm Q^\R(x)\mathrm G^\R(x)+x^{n-m+1}\mathrm R^\R(x)。

FR(x)≡QR(x)GR(x) mod xn−m+1\mathrm F^\R(x)\equiv\mathrm Q^\R(x)\mathrm G^\R(x) \bmod x^{n-m+1}。

QR(x)≡FR(x)GR(x) mod xn−m+1\mathrm Q^\R(x)\equiv\frac{\mathrm F^\R(x)}{\mathrm G^\R(x)}\bmod x^{n-m+1}。

QR(x) mod xn−m+1=QR(x)\mathrm Q^\R(x)\bmod x^{n-m+1}=\mathrm Q^\R(x)。

std::reverse(Q,Q+n−m+1)\text{std::reverse}(\mathrm Q,\mathrm Q+n-m+1)。

R(x)=F(x)−Q(x)G(x)\mathrm R(x)=\mathrm F(x)-\mathrm Q(x)\mathrm G(x)。


多项式对数

给定 F(x)\mathrm F(x),求 G(x)\mathrm G(x) 满足 G(x)≡ln⁡(F(x)) mod xn\mathrm G(x)\equiv \ln(\mathrm F(x))\bmod x^n。

log⁡b′a=1a×ln⁡(b)\log'_ba=\frac{1}{a\times\ln(b)}。

G′(x)≡ln⁡′(F(x))F′(x)=F′(x)F(x)\mathrm G'(x)\equiv\mathrm \ln'(\mathrm F(x))\mathrm F'(x)=\frac{\mathrm F'(x)}{\mathrm F(x)}。

∫G′(x)=G(x)\int \mathrm G'(x)=\mathrm G(x)。


多项式指数

给定 F(x)\mathrm F(x),求 G(x)\mathrm G(x) 满足 G(x)≡eF(x) mod xn\mathrm G(x)\equiv e^{\mathrm F(x)}\bmod x^n。* A0=0\mathrm A_0=0。


引理:

  1. 泰勒展开

求函数 F(x)\mathrm F(x) 某点的值。

F(x)∼G(x)=G(0)+F′(0)1!+F′′(0)2!+⋯\mathrm F(x)\sim \mathrm G(x)=\mathrm G(0)+\frac{\mathrm F'(0)}{1!}+\frac{\mathrm F''(0)}{2!}+\cdots。

  1. 牛顿迭代

给定函数 F(x)\mathrm F(x),求一个多项式 G\mathrm G,满足 F(G(x))≡0 mod xn\mathrm F(\mathrm G(x))\equiv0\bmod x^n。

首先,n=1n=1 时,F(G(x))=0 mod x\mathrm F(\mathrm G(x))=0\bmod x,这要单独算。

现在假设已经算出

F(G0(x))≡0 mod x⌈n2⌉\mathrm F(\mathrm G_0(x))\equiv0\bmod x^{\left\lceil\frac n 2\right\rceil}

考虑扩展到  mod xn\bmod x^n 下。可以把 F(G(x))\mathrm F(\mathrm G(x)) 在 G0(x)\mathrm G_0(x) 处泰勒展开

F(G(x))=F(G0(x))+(G(x)−G0(x))×F′(G0(x))1!+(G(x)−G0(x))2×F′′(G(x))2!+⋯\begin{align*} \mathrm F(\mathrm G(x))&=\mathrm F(\mathrm G_0(x))\\&+(\mathrm G(x)-\mathrm G_0(x))\times\frac{\mathrm F'(\mathrm G_0(x))}{1!}\\&+(\mathrm G(x)-\mathrm G_0(x))^2\times\frac{\mathrm F''(\mathrm G(x))}{2!}\\&+\cdots\end{align*}

因为 G(x)\mathrm G(x) 和 G0(x)\mathrm G_0(x) 的最后 ⌈n2⌉\left\lceil\frac n 2\right\rceil 项相同,所以 (G(x)−G0(x))2(\mathrm G(x)-\mathrm G_0(x))^2 的最低非 00 项系数大于 2⌈n2⌉2\left\lceil\frac n 2\right\rceil,所以可以得到

F(G(x))≡F(G0(x))+(G(x)−G0(x))×F′(G0(x)) mod xn\mathrm F(\mathrm G(x))\equiv\mathrm F(\mathrm G_0(x))+\mathrm (\mathrm G(x)-\mathrm G_0(x))\times \mathrm F'(\mathrm G_0(x))\bmod x^n

然后由于 F(G(x))≡0 mod xn\mathrm F(\mathrm G(x))\equiv 0\bmod x^n,可以得到

G(x)≡G0(x)−F(G0(x))F′(G0(x)) mod xn\mathrm G(x)\equiv\mathrm G_0(x)-\frac{\mathrm F(\mathrm G_0(x))}{\mathrm F'(\mathrm G_0(x))}\bmod x^n

G(x)=eF(x)\mathrm G(x)=e^{\mathrm F(x)}

ln⁡(G(x))−F(x)=0\ln (\mathrm G(x))-\mathrm F(x)=0

设 H(G(x))=ln⁡(G(x))−F(x)\mathrm H(\mathrm G(x))=\ln(\mathrm G(x))-\mathrm F(x)。

将 G(x)\mathrm G(x) 视为变量,F(x)\mathrm F(x) 视为常数。

H′(G(x))=1G(x)\mathrm H'(\mathrm G(x))=\frac 1{\mathrm G(x)}

G(x)≡G0(x)−H(G0(x))H′′(G0(x)) mod xn\mathrm G(x)\equiv\mathrm G_0(x)-\frac{\mathrm H(\mathrm G_0(x))}{\mathrm H''(\mathrm G_0(x))}\bmod x^n

G(x)≡(1−ln⁡(G0(x))+F(x))×G0(x) mod xn\mathrm G(x)\equiv\mathrm (1-\ln(\mathrm G_0(x))+\mathrm F(x))\times \mathrm G_0(x)\bmod x^n


多项式快速幂

给定 F(x),k\mathrm F(x),k,求 G(x)≡Fk(x) mod xn\mathrm G(x)\equiv \mathrm F^k(x)\bmod x^n。* A0=1\mathrm A_0=1。

exp⁡(k×ln⁡(F(x)))=e(ln⁡F(x))k=Fk(x)\exp (k\times\ln (\mathrm F(x)))=e^{{(\ln\mathrm F(x))}^k}=\mathrm F^k(x)。

多项式快速幂加强版(no *)

F→xstF′,F′(0)=1\mathrm F\to x^st\mathrm F', \mathrm F'(0)=1。

Fk=xsktkF′k\mathrm F^k=x^{sk}t^k\mathrm F'^k。

若 sk>nsk>n,则全为 00,否则将 F′k\mathrm F'^k 系数向后移动 sksk。


多项式开根

给定 F(x)\mathrm F(x),求 G(x)\mathrm G(x) 满足 G2(x)≡F(x) mod xn\mathrm G^2(x)\equiv\mathrm F(x)\bmod x^n。

对于 G0\mathrm G_0,求 F0\mathrm F_0 的二次剩余即可。

设 G02(x)≡F(x) mod x⌈n2⌉\mathrm G_0^2(x)\equiv \mathrm F(x)\bmod x^{\left\lceil\frac n 2\right\rceil},要求 G\mathrm G,G2(x)≡F(x) mod xn\mathrm G^2(x)\equiv\mathrm F(x)\bmod x^n。

则显然 (G(x)−G0(x))2≡0 mod xn(\mathrm G(x)-\mathrm G_0(x))^2\equiv0\bmod x^n。

G2(x)+G02(x)≡2G(x)G0(x) mod xn\mathrm G^2(x)+\mathrm G_0^2(x)\equiv 2\mathrm G(x)\mathrm G_0(x)\bmod x^n。

G(x)≡G02(x)+G2(x)2G0(x)≡G0(x)+F(x)2G0(x) mod xn\mathrm G(x)\equiv\frac{\mathrm G_0^2(x)+\mathrm G^2(x)}{2\mathrm G_0(x)}\equiv\frac{\mathrm G_0(x)+\mathrm F(x)}{2\mathrm G_0(x)}\bmod x^n。


多项式三角函数

给定 F(x)\mathrm F(x),求 G(x),H(x)\mathrm G(x),\mathrm H(x) 满足 G(x)≡sin⁡(F(x)),H(x)≡cos⁡(F(x)) mod xn\mathrm G(x)\equiv \sin(\mathrm F(x)),\mathrm H(x)\equiv\cos(\mathrm F(x))\bmod x^n。

请看欧拉公式:

eix=cos⁡x+isin⁡xe^{ix}=\cos x+i\sin x。

e−ix=cos⁡x−isin⁡xe^{-ix}=\cos x-i\sin x。

2cos⁡x=eix+e−ix2\cos x=e^{ix}+e^{-ix}。

2isin⁡x=eix−e−ix2i\sin x=e^{ix}-e^{-ix}。

cos⁡(F(x))=eiF(x)+e−iF(x)2\cos (\mathrm F(x))=\frac{e^{i\mathrm F(x)}+e^{-i\mathrm F(x)}}2。

sin⁡(F(x))=eiF(x)−e−iF(x)2i\sin(\mathrm F(x))=\frac{e^{i\mathrm F(x)}-e^{-i\mathrm F(x)}}{2i}。

i=ω41=G(P−1)/4i=\omega_4^1=G^{(P-1)/4}。


code:

paste

原文