🔍 数论进阶

Advanced Number Theory

模运算、同余方程、Fermat小定理、Euler定理、中国剩余定理……AMC 12 的数论题目比 AMC 10 深入得多,需要对抽象代数工具的灵活掌握。这些知识也是理解现代密码学的数学基础。

📚 3 章节 💡 5 道例题 ✏️ 6 道练习 🎯 难度:高 ⏱ 约55分钟
1
模运算 Modular Arithmetic
核心基础高频

1.1 模的定义与基本运算 Definition and Basic Operations

给定正整数 m,若 ab 除以 m 的余数相同,则称 ab 对模 m 同余,记作:

📝 同余定义 / Congruence Definition
a ≡ b (mod m)   ⇔   m | (a − b)
a is congruent to b modulo m if and only if m divides (a − b).

基本运算规则:

  • 加法:若 a ≡ b (mod m),c ≡ d (mod m),则 a + c ≡ b + d (mod m)
  • 乘法:若 a ≡ b (mod m),c ≡ d (mod m),则 ac ≡ bd (mod m)
  • 幂运算:若 a ≡ b (mod m),则 ak ≡ bk (mod m),对任意正整数 k 成立

Addition, multiplication, and exponentiation all preserve congruences. These rules are the foundation of all modular computation.

💡 邓老师提示:模运算的"取余"是 AMC 12 的基本功。注意:负数的取余在编程语言中规则不同,但数学上我们规定余数 0 ≤ r < m
In math, we always take the remainder r with 0 ≤ r < m. This convention matters in AMC problems!

1.2 同余的性质 Properties of Congruences

同余关系具有以下重要性质(等价于整数环的性质):

📝 同余基本性质 / Key Properties
自反性:a ≡ a (mod m)
对称性:若 a ≡ b (mod m),则 b ≡ a (mod m)
传递性:若 a ≡ b (mod m),b ≡ c (mod m),则 a ≡ c (mod m)
可加性:若 a ≡ b,c ≡ d (mod m),则 a±c ≡ b±d (mod m)
可乘性:若 a ≡ b,c ≡ d (mod m),则 ac ≡ bd (mod m)

模的消去律(关键!):

ac ≡ bc (mod m)gcd(c, m) = d,则 a ≡ b (mod m/d)

Cancellation in congruences requires dividing the modulus by gcd(c, m), not by m itself. This is a very common AMC 12 trick!

⚠️ 易错警示:普通等式中两边可同时除以一个非零数,但同余式中除法必须小心!只有当 gcd(c, m) = 1 时,才能从 ac ≡ bc (mod m) 直接推出 a ≡ b (mod m)。
You can only cancel c directly if gcd(c, m) = 1. Otherwise, divide the modulus as well!

1.3 线性同余方程 Linear Congruences

形如 ax ≡ b (mod m) 的方程称为线性同余方程。

📝 解的存在条件 / Solvability Condition
ax ≡ b (mod m) 有解  ⇔  gcd(a, m) | b
A linear congruence has solutions iff gcd(a, m) divides b.

求解方法:

  • 设 d = gcd(a, m)。若 d ∤ b,则无解。
  • 若 d | b,将方程两边同时除以 d:
    (a/d)x ≡ (b/d) (mod m/d)
  • 此时 gcd(a/d, m/d) = 1,可用扩展欧几里得算法求 (a/d) 的逆元,乘以 b/d 即得解。
📝 逆元 / Modular Multiplicative Inverse
若 ax ≡ 1 (mod m),则 x 是 a 在模 m 下的逆元,记作 a−1 (mod m)
逆元存在条件:gcd(a, m) = 1

扩展欧几里得算法求逆元:

求 a 在模 m 下的逆元,等价于求整数 x, y 使得 ax + my = gcd(a, m) = 1,此时 x 即为逆元。

💡 邓老师提示:扩展欧几里得算法是 AMC 12 的重要工具。可以用"辗转相除法倒推"手动计算,在竞赛中很有用。
2
数论定理 Classical Number Theory Theorems
核心高频

2.1 Fermat小定理 Fermat's Little Theorem (FLT)

📝 Fermat小定理 / FLT
若 p 为质数,且 p ∤ a,则 ap−1 ≡ 1 (mod p)
If p is prime and a is not divisible by p, then a^(p−1) ≡ 1 (mod p).

等价形式:对任意整数 a,ap ≡ a (mod p)(包括 a ≡ 0 mod p 的情况)。

An equivalent form: a^p ≡ a (mod p) for all integers a (this version includes the case a ≡ 0 mod p).

典型应用:求大数的模 p 余数、质数判定、证明某些数不是质数。

例:求 72025 mod 13。

解:13 是质数,7 ∤ 13。由 FLT:712 ≡ 1 (mod 13)。

2025 = 12 × 168 + 9,所以 72025 = (712)168 × 79 ≡ 1168 × 79 ≡ 79 (mod 13)。

继续化简:72 ≡ 49 ≡ 10 (mod 13),74 ≡ 102 ≡ 9 (mod 13),78 ≡ 92 ≡ 81 ≡ 3 (mod 13),所以 79 ≡ 78 × 7 ≡ 3 × 7 = 21 ≡ 8 (mod 13)。

⚠️ 重要注意:FLT 的逆命题不成立!若 an−1 ≡ 1 (mod n),不能推出 n 是质数(伪质数/Carmichael数)。AMC 12 中考的是 FLT 的直接应用,不需要反向判定。

2.2 Euler定理 Euler's Theorem

📝 Euler定理 / Euler's Theorem
若 gcd(a, n) = 1,则 aφ(n) ≡ 1 (mod n)
If gcd(a, n) = 1, then a^(φ(n)) ≡ 1 (mod n).

其中 φ(n) 是 Euler φ 函数,表示 1 到 n 中与 n 互质的整数个数。

φ(n) 的计算公式:

  • 若 n = pk(p 为质数),φ(n) = pk − pk−1 = pk(1 − 1/p)
  • 若 n = p·q(p, q 为不同质数),φ(n) = (p−1)(q−1)
  • 若 n = p1a1 · p2a2 · ...,则 φ(n) = n · ∏(1 − 1/pi)

Euler's Theorem is a generalization of FLT. When n = p (prime), φ(p) = p − 1, so Euler's Theorem becomes FLT.

💡 邓老师提示:Euler 定理将 FLT 推广到任意模 n。在 AMC 12 中,求 φ(n) 的题目很常见,需要会分解 n 后用公式计算。

2.3 中国剩余定理 Chinese Remainder Theorem (CRT)

📝 中国剩余定理 / CRT
设 m1, m2, …, mk 两两互质,则同余方程组:
x ≡ a1 (mod m1)
x ≡ a2 (mod m2)
x ≡ ak (mod mk)
在模 M = m1m2⋯mk 下有唯一解。

求解方法(构造法):

设 M = m1m2⋯mk,Mi = M/mi,求 Mi 在模 mi 下的逆元 ti(即 Miti ≡ 1 (mod mi))。

则通解为:

📝 CRT 通解公式 / General Solution
x ≡ a1M1t1 + a2M2t2 + ⋯ + akMktk (mod M)

简化版(两个方程时):

解 x ≡ a (mod m),x ≡ b (mod n)(其中 m, n 互质):

x = a + m·[(b − a) · m−1 mod n],取最小非负解即得。

💡 邓老师提示:中国剩余定理在 AMC 12 中通常以"同时满足多个整除条件"的文字题形式出现,关键是识别出它并列出方程组。

2.4 Wilson定理 Wilson's Theorem

📝 Wilson定理 / Wilson's Theorem
p 为质数  ⇔  (p − 1)! ≡ −1 (mod p)
A positive integer p is prime if and only if (p − 1)! ≡ −1 (mod p).

这是质数判定的充要条件(比 FLT 的逆命题更强)。

重要推论:

  • 若 (p − 1)! ≡ −1 (mod p),则 p 一定是质数(但这计算量太大,不适合做大数判定)。
  • 在模 p 下,1, 2, …, p−1 的乘法逆元是配对的:i · (p−i) ≡ −1 (mod p)。

Wilson定理的推论:对于质数 p > 2,(p−1)! ≡ 1 · 2 · ... · (p−1) ≡ −1 (mod p),且在配对 (1, p−1), (2, p−2), ... 时,每对的乘积 ≡ −1 (mod p)。

⚠️ 注意:Wilson 定理的逆命题在理论上很漂亮,但计算 (p−1)! 对大数 p 来说完全不可行(阶乘增长极快)。AMC 12 中 Wilson 定理主要出现在需要"阶乘性质"的题目中。
3
进阶技巧 Advanced Techniques
竞赛进阶高难度

3.1 阶(Order)的概念 Order of an Integer

📝 阶的定义 / Order Definition
设 gcd(a, n) = 1,使 ak ≡ 1 (mod n) 成立的最小正整数 k,称为 a 在模 n 下的,记作 ordn(a)
The order of a modulo n is the smallest positive integer k such that a^k ≡ 1 (mod n).

基本性质:

  • ordn(a) 总是 φ(n) 的约数(由 Euler 定理:aφ(n) ≡ 1 mod n)
  • 若 at ≡ 1 (mod n),则 ordn(a) | t
  • 若 ordn(a) = d,则 a1, a2, …, ad 在模 n 下两两不同

The order always divides φ(n). This is a powerful tool for solving problems about cycles and periodicity in modular arithmetic.

💡 邓老师提示:"阶"的概念在离散对数问题中特别有用。AMC 12 的压轴题有时会用到阶的性质来做周期分析。

3.2 原根 Primitive Roots

📝 原根定义 / Primitive Root
若 ordn(g) = φ(n),则 g 是模 n 的一个原根(Primitive Root)
A primitive root g modulo n has order exactly φ(n).

原根的意义:从 g0, g1, …, gφ(n)−1 可以生成模 n 下所有与 n 互质的数。

原根的存在性:

模 n是否有原根Has Primitive Root?
2, 4, pk, 2pk(p 为奇质数)Yes
其他 nNo

重要性质:

  • 若 g 是模 p 的原根(p 为质数),则 {g1, g2, …, gp−1} 恰好构成模 p 乘法群的全部非零元素
  • 模 p 的原根个数为 φ(p−1)
⚠️ AMC 12 须知:原根的具体求解(暴力找)是可行的:从 2 开始检查 ordp(g) 是否等于 p−1。AMC 12 的原根题目通常只需要知道原根存在性的结论,不需要构造。

3.3 Legendre符号简介 Legendre Symbol

📝 Legendre符号 / Legendre Symbol
(a/p) = 1  ⇔  a 是模 p 的二次剩余,且 a ∤ p
(a/p) = −1  ⇔  a 是模 p 的二次非剩余
(a/p) = 0  ⇔  p | a
更精确地:(a/p) ≡ a(p−1)/2 (mod p),值为 ±1

核心性质:

  • 乘法性:(ab/p) = (a/p)(b/p)
  • Euler判别法:(a/p) ≡ a(p−1)/2 (mod p)
  • 二次互反律(Quadratic Reciprocity):若 p, q 为奇质数,则 (p/q)·(q/p) = (−1)((p−1)/2)·((q−1)/2)

Legendre's symbol tells us whether a is a quadratic residue (a perfect square) modulo a prime p. The law of quadratic reciprocity relates (p/q) and (q/p).

💡 邓老师提示:AMC 12 中 Legendre 符号的题目通常只需用到 Euler 判别法 a(p−1)/2 ≡ (a/p) (mod p),以及 (a/p) = 1 或 −1 的判定,不需要记忆二次互反律的全部细节。

3.4 Diophantine方程 Diophantine Equations

Diophantine 方程是指未知数只能取整数值的方程。AMC 12 中常见的类型包括:

① 线性Diophantine方程:ax + by = c

📝 线性Diophantine方程 / Linear Diophantine Equation
ax + by = c 有整数解  ⇔  gcd(a, b) | c
通解:设 d = gcd(a, b),则有一组特解 (x₀, y₀),通解为 x = x₀ + (b/d)·t,y = y₀ − (a/d)·t,t ∈ ℤ

② Pell方程:x² − ny² = 1(n为非完全平方数)

Pell 方程总是有无穷多组正整数解。其最小解 (x₁, y₁) 可以通过连分数展开求得。

Pell's equation has infinitely many solutions, and all solutions can be generated from the minimal solution via recurrence relations.

③ 指数型Diophantine(如 ax − by = c)

这类方程通常利用模运算来限制可能的解,再用枚举或因式分解求解。

💡 邓老师提示:AMC 12 中的 Diophantine 方程题,关键是先用 gcd/模运算缩小范围,再考虑特解构造或枚举。记住:"无解证明靠模运算,有解时靠构造"。
4
例题精讲 Worked Examples
5 题含历年真题
📌 例题 1 模运算 · FLT

求 2100 mod 13 的值。 Find 2100 mod 13.

解题思路:Fermat小定理
13 是质数,由 FLT:212 ≡ 1 (mod 13)。
100 = 12 × 8 + 4,所以 2100 = (212)8 × 24 ≡ 18 × 16 ≡ 16 ≡ 3 (mod 13)。
By FLT: 212 ≡ 1 (mod 13). 100 = 12×8+4, so 2100 ≡ 24 ≡ 16 ≡ 3 (mod 13).
📌 例题 2 线性同余方程

求满足 5x ≡ 3 (mod 12) 的最小正整数 x。 Find the smallest positive integer x satisfying 5x ≡ 3 (mod 12).

解题思路:求逆元
gcd(5, 12) = 1,所以 5 在模 12 下有逆元。
求逆元:5 × ? ≡ 1 (mod 12),5 × 5 = 25 ≡ 1 (mod 12),所以 5−1 ≡ 5。
两边乘以 5−1:x ≡ 3 × 5 ≡ 15 ≡ 3 (mod 12)。
gcd(5,12)=1. Find 5−1 ≡ 5 (mod 12). Then x ≡ 3×5 ≡ 15 ≡ 3 (mod 12).
📌 例题 3 中国剩余定理

求同余方程组 x ≡ 2 (mod 3),x ≡ 3 (mod 5),x ≡ 2 (mod 7) 的最小正整数解。 Find the smallest positive solution of the system: x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7).

解题思路:CRT逐次代入
M = 3×5×7 = 105。
M1 = 35,逆元 35−1 ≡ 35−1 ≡ 2 (mod 3)(因为 35 ≡ 2,2×2=4≡1)
M2 = 21,逆元 21−1 ≡ 21−1 ≡ 1 (mod 5)(21≡1)
M3 = 15,逆元 15−1 ≡ 1 (mod 7)(15≡1)
x ≡ 2×35×2 + 3×21×1 + 2×15×1 = 140 + 63 + 30 = 233 ≡ 233−210 = 23 (mod 105)。
M = 105. x = 2×35×2 + 3×21×1 + 2×15×1 = 233 ≡ 23 (mod 105). Smallest positive solution is 23.
📌 例题 4 Euler定理 · φ函数

求 φ(72) 的值。 Find φ(72).

解题思路:φ函数公式
72 = 23 × 32
φ(72) = 72 × (1 − 1/2) × (1 − 1/3) = 72 × 1/2 × 2/3 = 72 × 1/3 = 24
72 = 2³ × 3². φ(72) = 72 × (1−½)(1−⅓) = 72 × ½ × ⅔ = 24.
📌 例题 5 线性Diophantine方程

方程 6x + 15y = 21 是否有整数解?若有,求出一组正整数解。 Does 6x + 15y = 21 have integer solutions? If yes, find one with positive integers.

解题思路:gcd判别 + 特解构造
gcd(6, 15) = 3,3 | 21,所以有整数解。
找特解:6×(−4) + 15×3 = −24 + 45 = 21,所以 (x₀, y₀) = (−4, 3)。
通解:x = −4 + (15/3)·t = −4 + 5t,y = 3 − (6/3)·t = 3 − 2t,t ∈ ℤ。
若要求正整数,取 t=1 得 x=1, y=1(也是正整数解)。
gcd(6,15)=3|21, so solutions exist. Try x=−4, y=3: 6(−4)+15(3)=−24+45=21. General: x=−4+5t, y=3−2t. With t=1: x=1, y=1.
5
巩固练习 Practice Problems
6 题提交即判

第1题 32024 mod 7 的值是多少? What is 32024 mod 7?

第2题 同余方程 4x ≡ 6 (mod 10) 有多少个模10下互不相同的解? How many distinct solutions modulo 10 does 4x ≡ 6 (mod 10) have?

第3题 求 φ(60) 的值。 Find φ(60).

第4题 用中国剩余定理求 x ≡ 1 (mod 4),x ≡ 2 (mod 3) 的最小正整数解。 Using CRT, find the smallest positive solution of x ≡ 1 (mod 4), x ≡ 2 (mod 3).

第5题 Wilson定理:若 p 是质数,(p−1)! mod p 的值是? By Wilson's theorem, if p is prime, what is (p−1)! mod p?

第6题 求满足 7x ≡ 5 (mod 12) 的最小正整数 x。 Find the smallest positive x satisfying 7x ≡ 5 (mod 12).