前言:
作为一名OIer,数学推导一定不能差。
例子:
用尽量快的方法求以下式子:
- ∑ i = 0 n − 1 a i ∗ b n − 1 − i ( n ∈ N + ) \sum_{i=0}^{n-1} a^i*b^{n-1-i}~~~ (n \in N_+) ∑i=0n−1ai∗bn−1−i (n∈N+)
- ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i ( 2 ∣ n ) \sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i~~~~ (2|n) ∑i=0n−1(−1)i∗an−1−i∗bi (2∣n)
- ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i ( n = 2 k + 1 , k ∈ N + ) \sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i~~~~ (n=2k+1,k\in N_+) ∑i=0n−1(−1)i∗an−1−i∗bi (n=2k+1,k∈N+)
- ∑ i = 1 n i 2 \sum_{i=1}^n i^2 ∑i=1ni2
用 ∑ \sum ∑只是为了好看,建议读者把求和式展开。
公式:
- a n − b n = ( a − b ) ∗ ∑ i = 0 n − 1 a i ∗ b n − 1 − i ( n ∈ N + ) a^n-b^n=(a-b)*\sum_{i=0}^{n-1} a^i*b^{n-1-i}~~~ (n \in N_+) an−bn=(a−b)∗∑i=0n−1ai∗bn−1−i (n∈N+)
- a n − b n = ( a + b ) ∗ ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i ( 2 ∣ n ) a^n-b^n=(a+b)*\sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i~~~~ (2|n) an−bn=(a+b)∗∑i=0n−1(−1)i∗an−1−i∗bi (2∣n)
- a n + b n = ( a + b ) ∗ ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i ( n = 2 k + 1 , k ∈ N + ) a^n+b^n=(a+b)*\sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i~~~~ (n=2k+1,k\in N_+) an+bn=(a+b)∗∑i=0n−1(−1)i∗an−1−i∗bi (n=2k+1,k∈N+)
- ∑ i = 1 n i 2 = n ∗ ( n + 1 ) ∗ ( 2 n + 1 ) / 6 \sum_{i=1}^n i^2=n*(n+1)*(2n+1)/6 ∑i=1ni2=n∗(n+1)∗(2n+1)/6
推导:
1. a n − b n = ( a − b ) ∗ ∑ i = 0 n − 1 a i ∗ b n − 1 − i ( n ∈ N + ) ~~~~~~~~~~~~~~~~~~~a^n-b^n=(a-b)*\sum_{i=0}^{n-1} a^i*b^{n-1-i}~~~ (n \in N_+) an−bn=(a−b)∗∑i=0n−1ai∗bn−1−i (n∈N+)
右
边
=
∑
i
=
1
n
a
i
∗
b
n
−
i
−
∑
i
=
0
n
−
1
a
i
∗
b
n
−
i
右边=\sum_{i=1}^na^i*b^{n-i}-\sum_{i=0}^{n-1}a^i*b^{n-i}
右边=i=1∑nai∗bn−i−i=0∑n−1ai∗bn−i
=
a
n
∗
b
0
−
a
0
∗
b
n
=
a
n
−
b
n
=a^n*b^0-a^0*b^n=a^n-b^n
=an∗b0−a0∗bn=an−bn
2. a n − b n = ( a + b ) ∗ ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i ( 2 ∣ n ) ~~~~~~~~~~~a^n-b^n=(a+b)*\sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i~~~~ (2|n) an−bn=(a+b)∗∑i=0n−1(−1)i∗an−1−i∗bi (2∣n)
右 边 = ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − i ∗ b i − ∑ i = 1 n ( − 1 ) i − 1 ∗ a n − i ∗ b i = a n − b n 右边=\sum_{i=0}^{n-1}(-1)^i*a^{n-i}*b^i-\sum_{i=1}^n(-1)^{i-1}*a^{n-i}*b^i=a^n-b^n 右边=i=0∑n−1(−1)i∗an−i∗bi−i=1∑n(−1)i−1∗an−i∗bi=an−bn
3. 类似2的证明。
4. ∑ i = 1 n i 2 = n ∗ ( n + 1 ) ∗ ( 2 n + 1 ) / 6 ~~~~~~~~\sum_{i=1}^n i^2=n*(n+1)*(2n+1)/6 ∑i=1ni2=n∗(n+1)∗(2n+1)/6
n
3
−
(
n
−
1
)
3
=
1
∗
[
n
2
+
(
n
−
1
)
2
+
n
(
n
−
1
)
]
n^3-(n-1)^3=1*[n^2+(n-1)^2+n(n-1)]
n3−(n−1)3=1∗[n2+(n−1)2+n(n−1)]
=
n
2
+
(
n
−
1
)
2
+
n
2
−
n
=n^2+(n-1)^2+n^2-n
=n2+(n−1)2+n2−n
=
2
∗
n
2
+
(
n
−
1
)
2
−
n
=2*n^2+(n-1)^2-n
=2∗n2+(n−1)2−n
n
3
−
1
3
=
n
3
−
(
n
−
1
)
3
+
(
n
−
1
)
3
−
(
n
−
2
)
3
…
…
+
2
3
−
1
3
n^3-1^3=n^3-(n-1)^3+(n-1)^3-(n-2)^3……+2^3-1^3
n3−13=n3−(n−1)3+(n−1)3−(n−2)3……+23−13
n
3
−
1
3
=
2
∗
(
2
2
+
3
2
+
.
.
.
+
n
2
)
+
[
1
2
+
2
2
+
.
.
.
+
(
n
−
1
)
2
]
−
(
2
+
3
+
4
+
.
.
.
+
n
)
n^3-1^3=2*(2^2+3^2+...+n^2)+[1^2+2^2+...+(n-1)^2]-(2+3+4+...+n)
n3−13=2∗(22+32+...+n2)+[12+22+...+(n−1)2]−(2+3+4+...+n)
n
3
−
1
=
2
∗
(
1
2
+
2
2
+
3
2
+
.
.
.
+
n
2
)
−
2
+
[
1
2
+
2
2
+
.
.
.
+
(
n
−
1
)
2
+
n
2
]
−
n
2
−
(
2
+
3
+
4
+
.
.
.
+
n
)
n^3-1=2*(1^2+2^2+3^2+...+n^2)-2+[1^2+2^2+...+(n-1)^2+n^2]-n^2-(2+3+4+...+n)
n3−1=2∗(12+22+32+...+n2)−2+[12+22+...+(n−1)2+n2]−n2−(2+3+4+...+n)
n
3
−
1
=
3
∗
(
1
2
+
2
2
+
3
2
+
.
.
.
+
n
2
)
−
2
−
n
2
−
(
1
+
2
+
3
+
.
.
.
+
n
)
+
1
n^3-1=3*(1^2+2^2+3^2+...+n^2)-2-n^2-(1+2+3+...+n)+1
n3−1=3∗(12+22+32+...+n2)−2−n2−(1+2+3+...+n)+1
n
3
−
1
=
3
(
1
2
+
2
2
+
.
.
.
+
n
2
)
−
1
−
n
2
−
n
(
n
+
1
)
/
2
n^3-1=3(1^2+2^2+...+n^2)-1-n^2-n(n+1)/2
n3−1=3(12+22+...+n2)−1−n2−n(n+1)/2
3
(
1
2
+
2
2
+
.
.
.
+
n
2
)
=
n
3
+
n
2
+
n
(
n
+
1
)
/
2
=
(
n
/
2
)
(
2
n
2
+
2
n
+
n
+
1
)
=
(
n
/
2
)
(
n
+
1
)
(
2
n
+
1
)
3(1^2+2^2+...+n^2)=n^3+n^2+n(n+1)/2=(n/2)(2n^2+2n+n+1) =(n/2)(n+1)(2n+1)
3(12+22+...+n2)=n3+n2+n(n+1)/2=(n/2)(2n2+2n+n+1)=(n/2)(n+1)(2n+1)
1
2
+
2
2
+
3
2
+
.
.
.
+
n
2
=
n
(
n
+
1
)
(
2
n
+
1
)
/
6
1^2+2^2+3^2+...+n^2=n(n+1)(2n+1)/6
12+22+32+...+n2=n(n+1)(2n+1)/6
结论:
- ∑ i = 0 n − 1 a i ∗ b n − 1 − i = ( a n − b n ) / ( a − b ) ( n ∈ N + ) \sum_{i=0}^{n-1} a^i*b^{n-1-i}=(a^n-b^n)/(a-b)~~~ (n \in N_+) ∑i=0n−1ai∗bn−1−i=(an−bn)/(a−b) (n∈N+)
- ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i = ( a n − b n ) / ( a + b ) ( 2 ∣ n ) \sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i=(a^n-b^n)/(a+b)~~~~ (2|n) ∑i=0n−1(−1)i∗an−1−i∗bi=(an−bn)/(a+b) (2∣n)
- ∑ i = 0 n − 1 ( − 1 ) i ∗ a n − 1 − i ∗ b i = ( a n + b n ) / ( a + b ) ( n = 2 k + 1 , k ∈ N + ) \sum_{i=0}^{n-1}(-1)^i*a^{n-1-i}*b^i=(a^n+b^n)/(a+b)~~~~ (n=2k+1,k\in N_+) ∑i=0n−1(−1)i∗an−1−i∗bi=(an+bn)/(a+b) (n=2k+1,k∈N+)
- ∑ i = 1 n i 2 = n ∗ ( n + 1 ) ∗ ( 2 n + 1 ) / 6 \sum_{i=1}^n i^2=n*(n+1)*(2n+1)/6 ∑i=1ni2=n∗(n+1)∗(2n+1)/6
1~3 都 由 可 以 用 快 速 幂 从 O ( n ) 优 化 到 O ( l o g n ) . 都由可以用快速幂从O(n)优化到O(log ~n). 都由可以用快速幂从O(n)优化到O(log n).
4由 O ( n ) 优 化 成 O ( 1 ) O(n)优化成O(1) O(n)优化成O(1).
推广:
如果1~3要求取模,那就用快速幂+乘法逆元。