接下来求解前缀幂次和
求解 (sum_{i = 1}^{k} i^k)
[egin{aligned}
(p+1)^k - 1 = (p+1)^k - p^k + p^k - (p-1)^k + dots + p^1 - 1 \
(p+1)^k - p^k = sum_{i=0}^{k-1} inom{k}{i} p^i \
(p+1)^k - 1 = sum_{j=1}^{p} sum_{i=0}^{k-1} inom{k}{i} j^i = sum_{i=0}^{k-1} inom{k}{i} sum_{j=1}^{p} j^i
end{aligned}
]
设 (Psum(p, k) = sum_{i = 1} ^ {p} i ^ k) 即 (k) 次幂的前缀和
[egin{aligned}
(p+1)^{k+1} - 1 = sum_{i=0}^{k} inom{k+1}{i} Psum(p, i) \
Psum(p, k) = frac{ (p+1)^{k+1} - 1 - sum_{i=0}^{k-1} inom{k+1}{i} Psum(p, i) }{ inom{k+1}{k} } \
end{aligned}
]
这样就是跟 (p) 无关了, (O(k ^ 2)) 暴力推