.
题目:计算
∑
i
=
1
n
r
i
∗
i
k
\sum_{i=1}^nr^i*i^k
i=1∑nri∗ik其中
n
≤
1
0
9
,
k
≤
1
0
3
n\le10^9,k\le10^3
n≤109,k≤103
一个非常巧妙的转化,设
S
(
x
)
=
∑
i
=
1
n
r
i
∗
i
x
S(x)=\sum_{i=1}^nr^i*i^x
S(x)=i=1∑nri∗ix
我们要求的就是
S
(
k
)
S(k)
S(k)
考虑将式子变形
S
(
k
)
=
∑
i
=
1
n
r
i
∗
i
k
S(k)=\sum_{i=1}^nr^i*i^k
S(k)=i=1∑nri∗ik
r
S
(
k
)
=
∑
i
=
2
n
+
1
r
i
∗
(
i
−
1
)
k
rS(k)=\sum_{i=2}^{n+1}r^i*(i-1)^k
rS(k)=i=2∑n+1ri∗(i−1)k
(
r
−
1
)
S
(
k
)
=
n
k
∗
r
n
+
1
−
r
+
∑
i
=
2
n
r
i
∗
(
(
i
−
1
)
k
−
i
k
)
(r-1)S(k)=n^k*r^{n+1}-r+\sum_{i=2}^nr^i*((i-1)^k-i^k)
(r−1)S(k)=nk∗rn+1−r+i=2∑nri∗((i−1)k−ik)
后面部分用二项式展开
∑
i
=
2
n
r
i
∗
(
(
i
−
1
)
k
−
i
k
)
\sum_{i=2}^nr^i*((i-1)^k-i^k)
i=2∑nri∗((i−1)k−ik)
=
∑
i
=
2
n
r
i
∗
∑
j
=
0
k
−
1
C
k
j
∗
(
−
1
)
k
−
j
∗
i
j
=\sum_{i=2}^nr^i*\sum_{j=0}^{k-1}C_k^j*(-1)^{k-j}*i^j
=i=2∑nri∗j=0∑k−1Ckj∗(−1)k−j∗ij
=
∑
j
=
0
k
−
1
C
k
j
∗
(
−
1
)
k
−
j
∑
i
=
2
n
r
i
∗
i
j
=\sum_{j=0}^{k-1}C_k^j*(-1)^{k-j}\sum_{i=2}^nr^i*i^j
=j=0∑k−1Ckj∗(−1)k−ji=2∑nri∗ij
=
∑
j
=
0
k
−
1
C
k
j
∗
(
−
1
)
k
−
j
∗
(
S
(
j
)
−
r
)
=\sum_{j=0}^{k-1}C_k^j*(-1)^{k-j}*(S(j)-r)
=j=0∑k−1Ckj∗(−1)k−j∗(S(j)−r)
于是可以
O
(
n
2
)
O(n^2)
O(n2)递推
序列求和V2
最新推荐文章于 2021-09-26 20:14:56 发布