生成函数小结
目录
常见普通型生成函数($OGF$)
形如$F(x)=\sum_{i=0}^{\infty}f_ix^i$:
$$\begin{align*}
&<1,0,0,\cdots>[i==0]&1\\
&<1,1,1,\cdots>1&\frac{1}{1-x}\\
&<1,2,3,\cdots>i&\frac{1}{(1-x)^2}\\
&<1,-1,1,-1,\cdots>(-1)^i&\frac{1}{1-x}\\
&<0,1,\frac{1}{2},\frac{1}{3},\cdots>\frac{1}{i}(0<i)&-\ln(1-x)\\
&<1,1,\frac{1}{2},\frac{1}{6},\frac{1}{24},\cdots>\frac{1}{i!}&e^x\\
&<1,a,a^2,a^3,\cdots>a^i&\frac{1}{1-ax}\\
&<\binom{n}{0},\binom{n}{1},\binom{n}{2},\cdots>\binom{n}{i}&(1+x)^n\\
&<\binom{n-1}{0},\binom{n}{1},\binom{n+1}{2},\cdots>\binom{n-i+1}{i}&\frac{1}{(1-x)^n}\\
&<0,a,\frac{a^2}{2},\frac{a^3}{3},\cdots>\frac{a^i}{i}(0<i)&-\ln(1-ax)\\
\end{align*}$$
常见指数型生成函数($EGF$)
形如$F(x)=\sum_{i=0}^{\infty}\frac{f_i}{i!}x^i$:
$$\begin{align*}
&<1,1,1,\cdots>1&e^x\\
&<0,1,2,3,\cdots>i&xe^x\\
&<1,a,a^2,a^3,\cdots>a^i&e^{ax}\\
&<1,a,a^{\underline{2}},a^{\underline{3}},\cdots>a^{\underline{i}}&(1+x)^a\\
&<0,1,0,-1,0,1,0,-1,\cdots>[2\nmid i](-1)^{\frac{i-1}{2}}&\sin(x)\\
&<1,0,-1,0,1,0,-1,0,\cdots>[2|i](-1)^{\frac{i}{2}}&\cos(x)\\
\end{align*}$$
自然数幂和
求数列$k$次方和
给定数列$a$,对于任一$1 \leqslant k \leqslant m$求$\sum_{i=1}^na_i^k$
考虑其生成函数,则有:$$\begin{align*}F(x)&=\sum_{j=0}^{\infty}\sum_{i=1}^na_i^jx^j\\&=\sum_{i=1}^n\sum_{j=0}^{\infty}(a_ix)^j\\&=\sum_{i=1}^n\frac{1}{1-a_ix}\\&=\sum_{i=1}^n1+\frac{a_ix}{1-a_ix}\\&=n-x\sum_{i=1}^n\frac{-a_ix}{1-a_ix}\\&=n-x\sum_{i=1}^n\ln'(1-a_ix)\\&=n-x\ln'(\prod_{i=1}^n(1-a_ix))\end{align*}$$
$\prod_{i=1}^n(1-a_ix)$分治FFT即可
$O(N\log^2N)$