以下内容均在自然数范围讨论
1. 同余
1.1. 由定义得
( 1 ) k p + r ≡ r ( m o d p ) ( 2 ) 若 a ≡ b ( m o d p ) 且 a ≤ b ,则 p ∣ ( b − a ) (1)kp+r \equiv r \pmod p \\ (2)若a\equiv b \pmod p且a \le b,则p|(b-a) (1)kp+r≡r(modp)(2)若a≡b(modp)且a≤b,则p∣(b−a)
1.2. 加法和减法
a
±
b
≡
a
m
o
d
p
±
b
m
o
d
p
(
m
o
d
p
)
a\pm b \equiv a \bmod p\pm b \bmod p \pmod p
a±b≡amodp±bmodp(modp)
证明:
设
a
=
k
a
p
+
a
′
b
=
k
b
p
+
b
′
∴
a
m
o
d
p
=
a
′
,
b
m
o
d
p
=
b
′
,
a
±
b
=
(
k
a
±
k
b
)
p
+
a
′
±
b
′
∴
a
±
b
≡
a
′
±
b
′
(
m
o
d
p
)
∴
a
±
b
≡
a
m
o
d
p
±
b
m
o
d
p
(
m
o
d
p
)
设a=k_ap+a' \\ b=k_bp+b' \\ \therefore a \bmod p=a',b \bmod p=b', \\ a\pm b=(k_a\pm k_b)p+a'\pm b' \\ \therefore a\pm b \equiv a'\pm b' \pmod p \\ \therefore a\pm b\equiv a \bmod p \pm b\bmod p \pmod p
设a=kap+a′b=kbp+b′∴amodp=a′,bmodp=b′,a±b=(ka±kb)p+a′±b′∴a±b≡a′±b′(modp)∴a±b≡amodp±bmodp(modp)
1.3. 乘法
a
b
≡
(
a
m
o
d
p
)
(
b
m
o
d
p
)
(
m
o
d
p
)
ab \equiv (a\bmod p)(b\bmod p) \pmod p
ab≡(amodp)(bmodp)(modp)
证明:
设
a
=
k
a
p
+
a
′
b
=
k
b
p
+
b
′
∴
a
m
o
d
p
=
a
′
,
b
m
o
d
p
=
b
′
,
a
b
=
(
k
a
p
+
a
′
)
(
k
b
p
+
b
′
)
=
k
a
k
b
p
2
+
k
a
b
′
p
+
k
b
a
′
p
+
a
′
b
′
∴
a
b
≡
a
′
b
′
(
m
o
d
p
)
∴
a
b
≡
(
a
m
o
d
p
)
(
b
m
o
d
p
)
(
m
o
d
p
)
设a=k_ap+a' \\ b=k_bp+b' \\ \therefore a \bmod p=a',b \bmod p=b', \\ ab=(k_ap+a')(k_bp+b')=k_ak_bp^2+k_ab'p+k_ba'p+a'b' \\ \therefore ab \equiv a'b' \pmod p \\ \therefore ab \equiv (a\bmod p)(b\bmod p) \pmod p
设a=kap+a′b=kbp+b′∴amodp=a′,bmodp=b′,ab=(kap+a′)(kbp+b′)=kakbp2+kab′p+kba′p+a′b′∴ab≡a′b′(modp)∴ab≡(amodp)(bmodp)(modp)
2. 费马小定理
若
p
为素数且
g
c
d
(
a
,
p
)
=
1
则
a
p
−
1
≡
1
(
m
o
d
p
)
若p为素数且\mathrm{gcd}(a,p)=1 \\ 则a^{p-1}\equiv 1 \pmod p
若p为素数且gcd(a,p)=1则ap−1≡1(modp)
证明:
设
f
(
i
)
=
i
,
g
(
i
)
=
i
a
,
(
i
∈
[
1
,
p
−
1
]
∩
Z
)
∴
{
y
∣
y
=
f
(
i
)
m
o
d
p
}
=
[
1
,
p
−
1
]
∩
Z
设
1
≤
j
<
k
≤
p
−
1
∵
g
c
d
(
a
,
p
)
=
1
,
k
−
j
<
p
−
1
∴
(
k
−
j
)
a
≠
k
p
∴
g
(
k
)
−
g
(
j
)
≠
k
p
∴
g
(
k
)
≢
g
(
j
)
(
m
o
d
p
)
∵
g
(
i
)
m
o
d
p
∈
[
1
,
p
−
1
]
∩
Z
∴
{
y
∣
y
=
g
(
i
)
m
o
d
p
}
=
[
1
,
p
−
1
]
∩
Z
∴
∏
f
(
i
)
≡
∏
g
(
i
)
(
m
o
d
p
)
∴
(
p
−
1
)
!
≡
(
p
−
1
)
!
a
p
−
1
(
m
o
d
p
)
∴
(
p
−
1
)
!
(
a
p
−
1
−
1
)
=
k
p
∵
p
是质数
∴
(
p
−
1
)
!
m
o
d
p
≠
0
∴
a
p
−
1
−
1
=
k
p
∴
a
p
−
1
−
1
≡
0
(
m
o
d
p
)
∴
a
p
−
1
≡
1
(
m
o
d
p
)
设f(i)=i,g(i)=ia,(i\in[1,p-1]\cap Z) \\ \therefore\{y|y=f(i)\bmod p\}=[1,p-1]\cap Z \\ 设1\le j<k\le p-1 \\ \because \mathrm{gcd}(a,p)=1,k-j<p-1 \\ \therefore (k-j)a\neq kp \\ \therefore g(k)-g(j)\neq kp \\ \therefore g(k)\not\equiv g(j) \pmod p \\ \because g(i)\bmod p \in[1,p-1]\cap Z \\ \therefore \{y|y=g(i)\bmod p\}=[1,p-1]\cap Z \\ \therefore \prod f(i) \equiv \prod g(i) \pmod p \\ \therefore (p-1)!\equiv (p-1)!a^{p-1} \pmod p \\ \therefore (p-1)!(a^{p-1}-1)=kp \\ \because p是质数 \\ \therefore (p-1)! \bmod p\neq 0 \\ \therefore a^{p-1}-1=kp \\ \therefore a^{p-1}-1 \equiv 0 \pmod p \\ \therefore a^{p-1}\equiv 1 \pmod p
设f(i)=i,g(i)=ia,(i∈[1,p−1]∩Z)∴{y∣y=f(i)modp}=[1,p−1]∩Z设1≤j<k≤p−1∵gcd(a,p)=1,k−j<p−1∴(k−j)a=kp∴g(k)−g(j)=kp∴g(k)≡g(j)(modp)∵g(i)modp∈[1,p−1]∩Z∴{y∣y=g(i)modp}=[1,p−1]∩Z∴∏f(i)≡∏g(i)(modp)∴(p−1)!≡(p−1)!ap−1(modp)∴(p−1)!(ap−1−1)=kp∵p是质数∴(p−1)!modp=0∴ap−1−1=kp∴ap−1−1≡0(modp)∴ap−1≡1(modp)
3. 逆元(除法取模)
若
p
为素数
a
b
≡
a
b
p
−
2
(
m
o
d
p
)
若p为素数\\ \frac{a}{b}\equiv ab^{p-2} \pmod p
若p为素数ba≡abp−2(modp)
证明
∵
b
p
−
1
≡
1
(
m
o
d
p
)
∴
b
⋅
b
p
−
2
≡
1
(
m
o
d
p
)
∴
a
b
b
⋅
b
p
−
2
≡
a
b
(
m
o
d
p
)
∴
a
b
p
−
2
≡
a
b
(
m
o
d
p
)
\because b^{p-1}\equiv 1 \pmod p \\ \therefore b\cdot b^{p-2}\equiv 1 \pmod p \\ \therefore \frac{a}{b}b\cdot b^{p-2}\equiv \frac{a}{b}\pmod p \\ \therefore ab^{p-2}\equiv \frac{a}{b} \pmod p
∵bp−1≡1(modp)∴b⋅bp−2≡1(modp)∴bab⋅bp−2≡ba(modp)∴abp−2≡ba(modp)