伯努利数(B_i)的生成函数定义如下
[B(z) = frac{ze^z}{e^z - 1} = sum_{i = 0} ^ {infty} B_i imes frac{z^i}{i!}
]
一次多项式求逆即可快速计算(B_i)
那么它有啥用呢
可以用来计算自然数幂和
我们记
[S_p(n) = sum_{i = 1} ^ {n} i^p
]
那么
[
egin{aligned}
A(z,n) &= sum_{p=0}^{infty} S_p(n) imes frac{z^p}{p!}\
&= sum_{p=0}^{infty} sum_{i=1}^{n} frac{(iz)^p}{p!}\
&= sum_{i=1}^{n} e^{iz} = frac{1-e^{nz}}{e^{-z}-1}\
&= frac{ze^z}{e^z - 1} imes frac{e^{nz} - 1}{z}\
&= B(z) imes frac{e^{nz} - 1}{z}\
&= sum_{j=0}^{infty} B_j imes frac{z^{j-1}}{j!} imes (sum_{k=1}^{infty}frac{(nz)^k}{k!})\
&= sum_{p=0}^{infty} (sum_{j=0}^{p} B_j imes frac{z^{j-1}}{j!} imes frac{(nz)^{p+1-j}}{(p+1-j)!})\
&= sum_{p=0}^{infty} z^p imes (sum_{j=0}^{p} frac{B_j imes n^{p+1-j}}{j! imes {(p+1-j)!}})\
&= sum_{p=0}^{infty} z^p imes frac{1}{p+1} imes frac{1}{p!} imes (sum_{j=0}^{p} B_j imes inom{p+1}{j} imes n^{p+1-j})\
end{aligned}
]
对比系数不难发现
[S_p(n) = frac{1}{p+1} imes sum_{j=0}^{p} inom{p+1}{j} imes B_j imes n^{p+1-j}
]
一道简单的应用
2018 Multi-University Training Contest 4 Delighful Formulas
根据题意列出式子:
[Ans = sum_{i = 1} ^ {N} {[gcd(i, N) = 1] sum_{j = 1} ^ {i} {j ^ K}}
]
莫比乌斯反演:
[
egin{aligned}
Ans & = sum_{d mid N} {mu(d) sum_{i = 1} ^ {N} {[d mid i] sum_{j = 1} ^ {i} {j ^ K}}} \
& = sum_{d mid N} {mu(d) sum_{i = 1} ^ {frac{N} {d}} sum_{j = 1} ^ {id} {j ^ K}}\
end{aligned}
]
定义 (F):
[F_p(N) = sum_{i = 1} ^ {N} {i ^ p}
]
显然 (F_p) 是 (p + 1) 阶多项式:
[F_p(N) = sum_{i = 0} ^ {p + 1} {a_{p, i} N ^ i}
]
利用 (F) 化简原式:
[
egin{aligned}
Ans & = sum_{d mid N} {mu(d) sum_{i = 1} ^ {frac{N} {d}} {F_K(id)}} \
& = sum_{d mid N} {mu(d) sum_{i = 1} ^ {frac{N} {d}} sum_{j = 0} ^ {K + 1} {a_{K, j} (id) ^ j}} \
& = sum_{d mid N} {mu(d) sum_{j = 0} ^ {K + 1} {a_{K, j} d ^ j sum_{i = 1} ^ {frac{N} {d}} {i ^ j}}} \
& = sum_{d mid N} {mu(d) sum_{j = 0} ^ {K + 1} {a_{K, j} d ^ j F_j(frac{N}{d})}} \
& = sum_{d mid N} {mu(d) sum_{j = 0} ^ {K + 1} {a_{K, j} d ^ j sum_{k = 0} ^ {j + 1} {a_{j, k} (frac{N} {d}) ^ k}}} \
& = sum_{d mid N} {mu(d) sum_{i = -1} ^ {K + 1} {d ^ i sum_{j = 0} ^ {K + 1} sum_{k = 0} ^ {j + 1} {[j - k = i] a_{K, j} a_{j, k} N ^ k}}} \
end{aligned}
]
定义 (G):
[G_i = sum_{j = 0} ^ {K + 1} sum_{k = 0} ^ {j + 1} {[j - k = i] a_{K, j} a_{j, k} N ^ k}
]
看题解发现这个是可以算的,只需要用伯努利数展开一下
[
egin{aligned}
G_i &= sum_{j = 0} ^ {K + 1} sum_{k = 0} ^ {j + 1} {[j - k = i] a_{K, j} a_{j, k} N ^ k}\
&= sum_{j = 0} ^ {K + 1} sum_{k = 0} ^ {j + 1} [j - k = i] B_{K + 1 - j} imes frac{K!}{j! imes (K + 1 - j)!} imes B_{j + 1 - k} imes frac{j!}{k! imes (j + 1 - k)!} imes N ^ k\
&= K! imes frac{B_{i+1}}{(i+1)!} imes sum_{j = 0} ^ {K + 1} sum_{k = 0} ^ {j + 1} [j - k = i] frac{B_{K + 1 - j}}{(K + 1 - j)!} imes frac{N^k}{k!}\
end{aligned}
]
容易发现这是一个卷积形式,NTT一次即可
那么答案就是
[
egin{aligned}
Ans & = sum_{d mid N} {mu(d) sum_{i = -1} ^ {K + 1} {d ^ i G_i}} \
& = sum_{i = -1} ^ {K + 1} {G_i sum_{d mid N} {mu(d) d ^ i}} \
& = sum_{i = -1} ^ {K + 1} {G_i prod_{p mid N} {(1 - p ^ i)}} \
end{aligned}
]
(O(KM))计算即可
总复杂度是(O(K(logK + M)))