文章目录
定理
①:类欧几里得算法
求 f ( a , b , c , n ) = ∑ i = 0 n ⌊ a × i + b c ⌋ f(a,b,c,n)=\sum_{i=0}^n\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor f(a,b,c,n)=i=0∑n⌊ca×i+b⌋
分类讨论
①:
a
≥
c
∣
∣
b
≥
c
a\ge c||b\ge c
a≥c∣∣b≥c
∑
i
=
0
n
⌊
a
×
i
+
b
c
⌋
=
∑
i
=
0
n
(
⌊
(
a
%
c
)
i
+
(
b
%
c
)
c
⌋
+
i
⌊
a
c
⌋
+
⌊
b
c
⌋
)
\sum_{i=0}^n\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor=\sum_{i=0}^n\bigg(\bigg\lfloor\frac{(a\%c)i+(b\%c)}{c}\bigg\rfloor+i\bigg\lfloor\frac{a}{c}\bigg\rfloor+\bigg\lfloor\frac{b}{c}\bigg\rfloor\bigg)
i=0∑n⌊ca×i+b⌋=i=0∑n(⌊c(a%c)i+(b%c)⌋+i⌊ca⌋+⌊cb⌋)
=
f
(
a
%
c
,
b
%
c
,
c
,
n
)
+
n
×
(
n
+
1
)
2
⌊
a
c
⌋
+
n
⌊
b
c
⌋
=f(a\%c,b\%c,c,n)+\frac{n\times(n+1)}{2}\bigg\lfloor\frac{a}{c}\bigg\rfloor+n\bigg\lfloor\frac{b}{c}\bigg\rfloor
=f(a%c,b%c,c,n)+2n×(n+1)⌊ca⌋+n⌊cb⌋
②:
a
<
c
&
&
b
<
c
a<c\&\&b<c
a<c&&b<c
Ⅰ
a
=
0
⇒
f
(
a
,
b
,
c
,
n
)
=
0
a=0\Rightarrow f(a,b,c,n)=0
a=0⇒f(a,b,c,n)=0
Ⅱ
a
≠
0
a≠0
a=0
∑
i
=
0
n
⌊
a
×
i
+
b
c
⌋
=
∑
i
=
0
n
∑
j
=
0
⌊
a
×
i
+
b
c
⌋
−
1
1
\sum_{i=0}^n\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor=\sum_{i=0}^n\sum_{j=0}^{\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor-1}1
i=0∑n⌊ca×i+b⌋=i=0∑nj=0∑⌊ca×i+b⌋−11
=
∑
j
=
0
⌊
a
∗
n
+
b
c
⌋
−
1
∑
i
=
0
n
[
j
<
⌊
a
×
i
+
b
c
⌋
]
=\sum_{j=0}^{\bigg\lfloor\frac{a*n+b}{c}\bigg\rfloor-1}\sum_{i=0}^n\bigg[j<\big\lfloor\frac{a\times i+b}{c}\big\rfloor\bigg]
=j=0∑⌊ca∗n+b⌋−1i=0∑n[j<⌊ca×i+b⌋]
=
∑
j
=
0
⌊
a
∗
n
i
+
b
c
⌋
−
1
∑
i
=
0
n
[
j
<
⌈
a
i
+
b
−
c
+
1
c
⌉
]
=\sum_{j=0}^{\bigg\lfloor\frac{a*ni+b}{c}\bigg\rfloor-1}\sum_{i=0}^n\bigg[j<\big\lceil\frac{ai+b-c+1}{c}\big\rceil\bigg]
=j=0∑⌊ca∗ni+b⌋−1i=0∑n[j<⌈cai+b−c+1⌉]
=
∑
j
=
0
⌊
a
×
i
+
b
c
⌋
−
1
∑
i
=
0
n
[
c
j
<
a
i
+
b
−
c
+
1
]
=\sum_{j=0}^{\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor-1}\sum_{i=0}^n\bigg[cj< ai+b-c+1\bigg]
=j=0∑⌊ca×i+b⌋−1i=0∑n[cj<ai+b−c+1]
=
∑
j
=
0
⌊
a
×
i
+
b
c
⌋
−
1
∑
i
=
0
n
[
c
j
−
b
+
c
−
1
<
a
i
]
=\sum_{j=0}^{\bigg\lfloor\frac{a\times i+b}{c}\bigg\rfloor-1}\sum_{i=0}^n\bigg[cj-b+c-1< ai\bigg]
=j=0∑⌊ca×i+b⌋−1i=0∑n[cj−b+c−1<ai]
=
∑
j
=
0
⌊
a
∗
n
+
b
c
⌋
−
1
∑
i
=
0
n
[
⌊
c
j
−
b
+
c
−
1
a
⌋
<
i
]
=\sum_{j=0}^{\bigg\lfloor\frac{a*n+b}{c}\bigg\rfloor-1}\sum_{i=0}^n\bigg[\big\lfloor\frac{cj-b+c-1}{a}\big\rfloor<i\bigg]
=j=0∑⌊ca∗n+b⌋−1i=0∑n[⌊acj−b+c−1⌋<i]
=
∑
j
=
0
⌊
a
∗
n
+
b
c
⌋
−
1
n
−
⌊
c
j
−
b
+
c
−
1
a
⌋
=\sum_{j=0}^{\bigg\lfloor\frac{a*n+b}{c}\bigg\rfloor-1}n-\big\lfloor\frac{cj-b+c-1}{a}\big\rfloor
=j=0∑⌊ca∗n+b⌋−1n−⌊acj−b+c−1⌋
=
n
⌊
a
∗
i
+
b
c
⌋
−
f
(
c
,
−
b
+
c
−
1
,
a
,
⌊
a
∗
n
+
b
c
⌋
−
1
)
=n\bigg\lfloor\frac{a*i+b}{c}\bigg\rfloor-f(c,-b+c-1,a,\bigg\lfloor\frac{a*n+b}{c}\bigg\rfloor-1)
=n⌊ca∗i+b⌋−f(c,−b+c−1,a,⌊ca∗n+b⌋−1)
又套用①情况求解
公式
①:等比数列求和
∑ k = 1 n x k = x − x n + 1 1 − x \sum_{k=1}^nx^k=\frac{x -x^{n+1}}{1-x} k=1∑nxk=1−xx−xn+1
令
S
n
=
∑
k
=
1
n
x
k
S_n=\sum_{k=1}^nx^k
Sn=∑k=1nxk
x
×
S
n
=
x
∑
k
=
1
n
x
k
=
∑
k
=
2
n
+
1
x
k
x\times S_n=x\sum_{k=1}^nx^k=\sum_{k=2}^{n+1}x^{k}
x×Sn=xk=1∑nxk=k=2∑n+1xk
两式相减即可
S
n
−
x
×
S
n
=
x
1
−
x
n
+
1
S_n-x\times S_n=x^1-x^{n+1}
Sn−x×Sn=x1−xn+1
S
n
=
x
−
x
n
+
1
1
−
x
S_n=\frac{x-x^{n+1}}{1-x}
Sn=1−xx−xn+1
②:等差数列一次方和
首项为 a a a,公差为 d d d,求前 n n n项等差数的和
∑ i = 1 n ( a + ( i − 1 ) d ) \sum_{i=1}^n\bigg(a+(i-1)d\bigg) i=1∑n(a+(i−1)d)
a
+
(
a
+
d
)
+
(
a
+
2
d
)
+
.
.
.
+
(
a
+
(
n
−
1
)
d
)
⏟
n
=
a
⋅
n
+
d
+
2
d
+
.
.
.
(
n
−
1
)
d
⏟
n
−
1
\underbrace{a+(a+d)+(a+2d)+...+(a+(n-1)d)}_{n}=a·n+\underbrace{d+2d+...(n-1)d}_{n-1}
n
a+(a+d)+(a+2d)+...+(a+(n−1)d)=a⋅n+n−1
d+2d+...(n−1)d
=
a
⋅
n
+
(
1
+
2
+
.
.
.
+
n
−
1
)
d
=
a
⋅
n
+
n
(
n
−
1
)
2
d
=a·n+(1+2+...+n-1)d=a·n+\frac{n(n-1)}{2}d
=a⋅n+(1+2+...+n−1)d=a⋅n+2n(n−1)d
③:等差数列二次方和
首项为 a a a,公差为 d d d,求前 n n n项等差数的平方的和
∑ i = 1 n ( a + ( i − 1 ) d ) 2 \sum_{i=1}^n\bigg(a+(i-1)d\bigg)^2 i=1∑n(a+(i−1)d)2
a
2
+
(
a
+
d
)
2
+
(
a
+
2
d
)
2
+
.
.
.
+
(
a
+
(
n
−
1
)
d
)
2
⏟
n
\underbrace{a^2+(a+d)^2+(a+2d)^2+...+(a+(n-1)d)^2}_{n}
n
a2+(a+d)2+(a+2d)2+...+(a+(n−1)d)2
=
a
2
+
(
a
2
+
2
a
d
+
1
2
d
2
)
+
(
a
2
+
4
a
d
+
2
2
d
2
)
+
.
.
.
+
(
a
2
+
2
(
n
−
1
)
a
d
+
(
n
−
1
)
2
d
2
)
⏟
n
=\underbrace{a^2+(a^2+2ad+1^2d^2)+(a^2+4ad+2^2d^2)+...+(a^2+2(n-1)ad+(n-1)^2d^2)}_{n}
=n
a2+(a2+2ad+12d2)+(a2+4ad+22d2)+...+(a2+2(n−1)ad+(n−1)2d2)
=
a
2
n
+
(
2
a
d
+
4
a
d
+
.
.
.
+
2
(
n
−
1
)
a
d
)
⏟
n
−
1
+
(
1
2
+
2
2
+
.
.
.
+
(
n
−
1
)
2
)
d
2
⏟
n
−
1
=a^2n+\underbrace{(2ad+4ad+...+2(n-1)ad)}_{n-1}+\underbrace{(1^2+2^2+...+(n-1)^2)d^2}_{n-1}
=a2n+n−1
(2ad+4ad+...+2(n−1)ad)+n−1
(12+22+...+(n−1)2)d2
=
a
2
n
+
(
1
+
2
+
.
.
.
+
(
n
−
1
)
)
2
a
d
+
(
n
−
1
)
n
(
2
n
−
1
)
6
d
2
=a^2n+(1+2+...+(n-1))2ad+\frac{(n-1)n(2n-1)}{6}d^2
=a2n+(1+2+...+(n−1))2ad+6(n−1)n(2n−1)d2
=
a
2
n
+
n
(
n
−
1
)
a
d
+
(
n
−
1
)
n
(
2
n
−
1
)
6
d
2
=a^2n+n(n-1)ad+\frac{(n-1)n(2n-1)}{6}d^2
=a2n+n(n−1)ad+6(n−1)n(2n−1)d2
结论
①: n & 1 = 1 ⇒ 3 ∣ ( 2 n − 2 ) n\&1=1\Rightarrow 3|(2^n-2) n&1=1⇒3∣(2n−2)
如果 n n n为奇数,有 2 n − 2 2^n-2 2n−2则为 3 3 3的倍数
将减法转化为加法,如果
2
n
+
1
=
3
k
2^n+1=3k
2n+1=3k成立,那么结论成立,现在来证明“如果”
分享两种方法
法1
设
n
=
2
m
+
1
n=2m+1
n=2m+1
2
n
+
1
=
2
2
m
+
1
+
1
=
(
2
2
m
+
1
−
2
2
m
−
1
)
+
(
2
2
m
−
1
−
2
2
m
−
3
)
+
.
.
.
+
(
2
3
−
2
1
)
+
(
2
−
1
)
2^n+1=2^{2m+1}+1=(2^{2m+1}-2^{2m-1})+(2^{2m-1}-2^{2m-3})+...+(2^3-2^1)+(2-1)
2n+1=22m+1+1=(22m+1−22m−1)+(22m−1−22m−3)+...+(23−21)+(2−1)
每个括号里面的数都是
3
3
3的倍数,得证
- 简单举例第一个括号
2 2 m + 1 − 2 2 m − 1 = 2 2 m − 1 ∗ ( 2 2 − 1 ) = 2 2 m − 1 ∗ 3 2^{2m+1}-2^{2m-1}=2^{2m-1}*(2^2-1)=2^{2m-1}*3 22m+1−22m−1=22m−1∗(22−1)=22m−1∗3
法2:数学归纳法
当
n
=
1
n=1
n=1时,有
2
n
+
1
=
3
2^n+1=3
2n+1=3,满足条件
当
n
=
k
n=k
n=k时,
k
k
k为奇,假设有
2
k
+
1
=
3
t
2^k+1=3t
2k+1=3t
当
n
=
k
+
2
n=k+2
n=k+2时,则有
2
n
+
1
=
2
k
+
2
+
1
=
4
∗
2
k
+
1
=
4
∗
(
3
t
−
1
)
+
1
=
12
t
−
3
=
3
∗
(
4
t
−
1
)
2^n+1=2^{k+2}+1=4*2^k+1=4*(3t-1)+1=12t-3=3*(4t-1)
2n+1=2k+2+1=4∗2k+1=4∗(3t−1)+1=12t−3=3∗(4t−1)
证毕
②: 1 2 + 2 2 + . . . + n 2 = n ( n + 1 ) ( 2 n + 1 ) 6 1^2+2^2+...+n^2=\frac{n(n+1)(2n+1)}{6} 12+22+...+n2=6n(n+1)(2n+1)
有
(
n
+
1
)
3
=
n
3
+
3
n
2
+
3
n
+
1
(n+1)^3=n^3+3n^2+3n+1
(n+1)3=n3+3n2+3n+1
{
2
3
=
1
3
+
3
∗
1
2
+
3
∗
1
+
1
3
3
=
2
3
+
3
∗
2
2
+
3
∗
2
+
1
.
.
.
n
3
=
(
n
−
1
)
3
+
3
∗
(
n
−
1
)
2
+
3
(
n
−
1
)
+
1
(
n
+
1
)
3
=
n
3
+
3
∗
n
2
+
3
∗
n
+
1
\begin{cases} 2^3=1^3+3*1^2+3*1+1\\ 3^3=2^3+3*2^2+3*2+1\\ ...\\ n^3=(n-1)^3+3*(n-1)^2+3(n-1)+1\\ (n+1)^3=n^3+3*n^2+3*n+1\\ \end{cases}
⎩⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎧23=13+3∗12+3∗1+133=23+3∗22+3∗2+1...n3=(n−1)3+3∗(n−1)2+3(n−1)+1(n+1)3=n3+3∗n2+3∗n+1
等式左右两边
n
n
n项全加起来
(
n
+
1
)
3
=
1
3
+
3
∗
(
1
2
+
2
2
+
.
.
.
+
n
2
)
+
3
∗
(
1
+
2
+
.
.
.
+
n
)
+
1
+
1
+
.
.
.
+
1
⏟
n
(n+1)^3=1^3+3*(1^2+2^2+...+n^2)+3*(1+2+...+n)+\underbrace{1+1+...+1}_{n}
(n+1)3=13+3∗(12+22+...+n2)+3∗(1+2+...+n)+n
1+1+...+1
⇔
(
1
2
+
2
2
+
.
.
.
+
n
2
)
=
(
n
+
1
)
3
−
1
3
−
3
∗
(
1
+
2
+
.
.
.
+
n
)
−
1
+
1
+
.
.
.
+
1
⏟
n
3
\Leftrightarrow (1^2+2^2+...+n^2)=\frac{(n+1)^3-1^3-3*(1+2+...+n)-\underbrace{1+1+...+1}_{n}}{3}
⇔(12+22+...+n2)=3(n+1)3−13−3∗(1+2+...+n)−n
1+1+...+1
⇔
(
1
2
+
2
2
+
.
.
.
+
n
2
)
=
n
3
+
3
∗
n
2
+
3
∗
n
+
1
−
1
−
3
∗
n
(
n
+
1
)
2
−
n
3
\Leftrightarrow (1^2+2^2+...+n^2)=\frac{n^3+3*n^2+3*n+1-1-3*\frac{n(n+1)}{2}-n}{3}
⇔(12+22+...+n2)=3n3+3∗n2+3∗n+1−1−3∗2n(n+1)−n
⇔
(
1
2
+
2
2
+
.
.
.
+
n
2
)
=
2
n
3
+
6
n
2
+
6
n
+
2
−
2
−
3
n
2
−
3
n
−
2
n
6
\Leftrightarrow (1^2+2^2+...+n^2)=\frac{2n^3+6n^2+6n+2-2-3n^2-3n-2n}{6}
⇔(12+22+...+n2)=62n3+6n2+6n+2−2−3n2−3n−2n
⇔
(
1
2
+
2
2
+
.
.
.
+
n
2
)
=
2
n
3
+
3
n
2
+
n
6
=
n
(
2
n
2
+
3
n
+
1
)
6
=
n
(
n
+
1
)
(
2
n
+
1
)
6
\Leftrightarrow (1^2+2^2+...+n^2)=\frac{2n^3+3n^2+n}{6}=\frac{n(2n^2+3n+1)}{6}=\frac{n(n+1)(2n+1)}{6}
⇔(12+22+...+n2)=62n3+3n2+n=6n(2n2+3n+1)=6n(n+1)(2n+1)