第 11 章

群、Lagrange 定理与费马小定理

从模运算中的可逆元素抽象出群,用左陪集把群切成等大的块,证明子群的阶整除群的阶,并用它推出费马小定理与欧拉定理。

Groups, Lagrange's Theorem and Fermat's Little Theorem

We abstract the invertible elements of modular arithmetic into groups, cut a group into equal-sized cosets to prove that a subgroup's order divides the group's order, and use that to derive Fermat's little theorem and Euler's theorem.

首发于 2025.12.18中 / EN
系统课程abstract-algebragroup-theorymodular-arithmeticfermat-theorem
语言
字号
目录
篇内目录

从「有没有逆元」到抽象结构

上一讲的问题是:给定 aa 与 nn,是否存在 bb 使 ab≡1(modn)ab\equiv1\pmod n?答案由最大公因数决定:gcd⁡(a,n)=1\gcd(a,n)=1 时有逆元,否则没有。这个结论是用扩展欧几里得算法得到的。

本讲换一个角度看同一件事:把「可逆」这件事升级成一整套代数结构。一旦建立群论的语言,许多看起来互不相关的定理——Lagrange 定理、费马小定理、欧拉定理——会变成同一个证明的不同写法。

时间轴

时间内容
0:00回顾模运算与乘法逆元
2:09群的定义:封闭、结合、单位元、逆元
6:19例子:Z\mathbb Z 加法、Z\mathbb Z 乘法(非群)、Q∖{0}\mathbb Q\setminus\{0\}
9:21有限群:Zn\mathbb Z_n 加法
10:28Zn∖{0}\mathbb Z_n\setminus\{0\} 在乘法下是群当且仅当 nn 是素数
15:08隐藏的群 Zn∗\mathbb Z_n^*:与 nn 互素的元素
17:09群的阶;$
22:15子群的定义
25:34Lagrange 定理的陈述与例子
30:41用左陪集证明 Lagrange 定理
47:02费马小定理及其群论证明
56:20费马小定理的组合证明(项链)
1:03:31欧拉定理
1:09:49域与多项式根数上限(为后续密码学铺垫)

群的定义

一个群是一个集合 GG 配上一个二元运算 ∗*,满足四条公理:

  1. 封闭性:a,b∈G⇒a∗b∈Ga,b\in G\Rightarrow a*b\in G。
  2. 结合律:(a∗b)∗c=a∗(b∗c)(a*b)*c=a*(b*c) 对一切 a,b,c∈Ga,b,c\in G 成立。
  3. 单位元:存在 e∈Ge\in G,使 e∗a=a∗e=ae*a=a*e=a 对一切 aa 成立。
  4. 逆元:对每个 a∈Ga\in G,存在 a−1∈Ga^{-1}\in G,使 a−1∗a=a∗a−1=ea^{-1}*a=a*a^{-1}=e。

如果还满足交换律 a∗b=b∗aa*b=b*a,就称 GG 为阿贝尔群(交换群)。

注意公理里没有要求「逆元唯一」「单位元唯一」——这些可以由公理推出。课程没有在这里证明,但这是群论的第一批练习。

例子与非例子

集合与运算是群?原因
Z\mathbb Z 与加法是单位元 00,逆元 −a-a,且交换
Z\mathbb Z 与乘法否22 的逆元 1/2∉Z1/2\notin\mathbb Z;00 也没有逆元
Q∖{0}\mathbb Q\setminus\{0\} 与乘法是逆元是倒数,单位元 11
Zn\mathbb Z_n 与模加法是单位元 00,逆元是 n−an-a
Zn∖{0}\mathbb Z_n\setminus\{0\} 与模乘法当且仅当 nn 为素数见下

为什么 Zn∖{0}\mathbb Z_n\setminus\{0\} 在乘法下是群当且仅当 nn 是素数

若 nn 为素数,则是群。 封闭性来自模乘法的定义:两个余数相乘后再取余数,仍是余数。结合律继承自整数乘法。单位元是 11。唯一不平凡的是逆元:由上一讲的引理,当 gcd⁡(a,n)=1\gcd(a,n)=1 时 aa 有逆元;若 nn 是素数且 a∈{1,…,n−1}a\in\{1,\dots,n-1\},则 gcd⁡(a,n)=1\gcd(a,n)=1,所以每个非零元素都可逆。

若 nn 为合数,则不是群。 取 n=pqn=pq(p,q>1p,q>1),则 p∈Zn∖{0}p\in\mathbb Z_n\setminus\{0\} 且 gcd⁡(p,n)=p≠1\gcd(p,n)=p\ne1。由同一引理的逆否命题,pp 没有乘法逆元,所以封闭的逆元公理失败。

这个例子说明:「是不是群」不只取决于集合,还取决于配了什么运算。

藏在里面的群

合数 nn 时,Zn∖{0}\mathbb Z_n\setminus\{0\} 不是群,但其中有一个子集是群:

Zn∗={a∈Zn:gcd⁡(a,n)=1}.\mathbb Z_n^*=\{a\in\mathbb Z_n:\gcd(a,n)=1\}.

它对乘法封闭(两个与 nn 互素的数相乘仍与 nn 互素),单位元是 11,每个元素由引理保证有逆元,而逆元也与 nn 互素。所以 Zn∗\mathbb Z_n^* 是群。这个群在后面讲 RSA 时会反复出现。

群的阶与两个计数

有限群 GG 的阶记作 ∣G∣|G|,就是元素个数。

  • ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1(pp 素数)。
  • ∣Zpq∗∣=(p−1)(q−1)|\mathbb Z_{pq}^*|=(p-1)(q-1)(p≠qp\ne q 为素数)。

第二个用容斥:11 到 pq−1pq-1 共 pq−1pq-1 个数,要减掉与 pqpq 不互素的。不互素意味着被 pp 或 qq 整除。qq 的倍数有 p−1p-1 个(q,2q,…,(p−1)qq,2q,\dots,(p-1)q),pp 的倍数有 q−1q-1 个,而 pqpq 的倍数在范围内不存在。于是

∣Zpq∗∣=(pq−1)−(p−1)−(q−1)=pq−p−q+1=(p−1)(q−1).|\mathbb Z_{pq}^*|=(pq-1)-(p-1)-(q-1)=pq-p-q+1=(p-1)(q-1).

这个数就是欧拉函数 φ(pq)\varphi(pq)。

子群

设 H⊆GH\subseteq G。若 HH 在同一个运算下也构成群,就称 HH 是 GG 的子群。

关键是「更强的封闭性」:对 a,b∈Ha,b\in H,不仅 a∗b∈Ga*b\in G(这由 GG 的封闭性自动成立),而且必须 a∗b∈Ha*b\in H;同样,a−1a^{-1} 也必须落在 HH 里。在 HH 内部做运算、求逆,永远不需要跑到 GG 的其余部分去。

例子。 G=Z7∖{0}G=\mathbb Z_7\setminus\{0\},∣G∣=6|G|=6。取 H={1,2,4}H=\{1,2,4\}。验证:1⋅2=21\cdot2=2,1⋅4=41\cdot4=4,2⋅4=8≡12\cdot4=8\equiv1,都在 HH 内;2−1=42^{-1}=4,4−1=24^{-1}=2,1−1=11^{-1}=1。

更省力的看法:HH 正好是 22 的幂次取模 77:

20=1,21=2,22=4,23=8≡1.2^0=1,\qquad 2^1=2,\qquad 2^2=4,\qquad 2^3=8\equiv1.

幂次相乘等于指数相加,所以封闭性自动成立;23=12^3=1 保证逆元存在(21⋅22=12^1\cdot2^2=1)。这是构造子群最常用的方式:取某个元素的全部幂。

Lagrange 定理

定理。 若 GG 是有限群,H≤GH\le G 是子群,则 ∣H∣|H| 整除 ∣G∣|G|。

这条定理的威力在于:它只用了群的四条公理,却对子群的可能大小给出了很强的限制。∣G∣=6|G|=6 时,子群的阶只能是 1,2,3,61,2,3,6;阶为 44 或 55 的子群根本不可能存在。

左陪集

对 x∈Gx\in G,定义

xH={xh:h∈H}.xH=\{xh:h\in H\}.

这是把 HH 整体「平移」xx 得到的集合,称为 xx 的左陪集。若 x∈Hx\in H,则 xH=HxH=H;若 x∉Hx\notin H,则得到 HH 的一个平移副本。

证明的两步

计划。 证明 GG 可以写成若干个左陪集的不交并:

G=x1H  ∪˙  x2H  ∪˙⋯∪˙  xkH,G=x_1H\;\dot\cup\;x_2H\;\dot\cup\cdots\dot\cup\;x_kH ,

其中每个陪集都与 HH 等大。于是 ∣G∣=k∣H∣|G|=k|H|,整除性得证。

具体做法是贪心:从尚未覆盖的元素中任取一个作为 x1x_1,取走 x1Hx_1H;再从剩余元素中任取 x2x_2,取走 x2Hx_2H;如此继续。

第一步:每个陪集与 HH 等势。 定义映射 h↦xhh\mapsto xh。它是单射:若 xh1=xh2xh_1=xh_2,左乘 x−1x^{-1} 并用结合律,

x−1(xh1)=x−1(xh2)  ⟹  (x−1x)h1=(x−1x)h2  ⟹  eh1=eh2  ⟹  h1=h2.x^{-1}(xh_1)=x^{-1}(xh_2) \;\Longrightarrow\; (x^{-1}x)h_1=(x^{-1}x)h_2 \;\Longrightarrow\; eh_1=eh_2 \;\Longrightarrow\; h_1=h_2 .

它是满射:陪集的定义就是所有 xhxh。所以 ∣xH∣=∣H∣|xH|=|H|。这个论证用了逆元、结合律和单位元——群的公理在这里全部出场。

第二步:两个不同的陪集不相交。 设 xiHx_iH 与 xjHx_jH 有公共元素,即存在 h1,h2∈Hh_1,h_2\in H 使

xih1=xjh2.x_ih_1=x_jh_2 .

右乘 h2−1h_2^{-1}:

xj=xih1h2−1.x_j=x_ih_1h_2^{-1}.

因为 HH 是子群,h2−1∈Hh_2^{-1}\in H,再由 HH 的封闭性 h1h2−1∈Hh_1h_2^{-1}\in H。所以 xj∈xiHx_j\in x_iH。

但 xjx_j 是贪心过程中「尚未被覆盖」时选出的元素,而 xiHx_iH 已经被取走,覆盖了 xjx_j——矛盾。因此不同陪集不可能相交。

两步合起来:GG 被切成 kk 个互不相交、大小都是 ∣H∣|H| 的块,故 ∣G∣=k∣H∣|G|=k|H|,即 ∣H∣∣∣G∣|H|\mid|G|。

费马小定理

定理。 若 pp 是素数,p∤ap\nmid a,则

ap−1≡1(modp).a^{p-1}\equiv1\pmod p .

推论。 ap−2a^{p-2} 是 aa 模 pp 的乘法逆元:ap−2⋅a=ap−1≡1a^{p-2}\cdot a=a^{p-1}\equiv1。这是除扩展欧几里得之外的第二种求逆元方法,只需幂运算。

证明

设 kk 是最小的正整数使 ak≡1(modp)a^k\equiv1\pmod p。

kk 存在。 考虑 a1,a2,a3,…a^1,a^2,a^3,\dots 模 pp 的余数。余数只有 pp 种可能,而序列无限长,由鸽巢原理必有两个指数 i<ji<j 使

ai≡aj(modp).a^i\equiv a^j\pmod p .

因为 pp 是素数且 p∤ap\nmid a,aa 可逆,两边乘以 a−ia^{-i} 得

aj−i≡1(modp).a^{j-i}\equiv1\pmod p .

取 k=j−ik=j-i 即可。这一步的关键是可逆性,而可逆性来自 pp 是素数。

幂次构成子群。 集合 H={a0,a1,…,ak−1}H=\{a^0,a^1,\dots,a^{k-1}\} 在乘法下封闭(指数相加,超过 kk 就减去 kk),单位元是 a0=1a^0=1,逆元是 ak−ma^{k-m}。所以 HH 是子群,且 ∣H∣=k|H|=k——kk 的定义保证 a0,…,ak−1a^0,\dots,a^{k-1} 互不相同。

用 Lagrange 收尾。 H≤Zp∖{0}H\le\mathbb Z_p\setminus\{0\},而 ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1。由 Lagrange 定理,k∣p−1k\mid p-1,设 p−1=ckp-1=ck。于是

ap−1=ack=(ak)c≡1c≡1(modp).a^{p-1}=a^{ck}=(a^k)^c\equiv1^c\equiv1\pmod p .

证明结束。注意整个论证只用了两件事:aa 可逆(保证 kk 存在)与 Lagrange 定理(保证 k∣p−1k\mid p-1)。

另一种证明:项链计数

费马小定理等价于 p∣ap−ap\mid a^p-a(两边乘 aa)。取 a=2a=2、p=5p=5 做具体说明。

用红蓝两种珠子串成长度 55 的项链(首尾相接),共有 25=322^5=32 条串。把串首尾粘起来、旋转视为同一条项链。一条非单色项链旋转一次会得到 55 条不同的串,因为 55 是素数,非单色串没有非平凡的旋转对称;单色项链只有全红、全蓝两条,每条只对应 11 条串。于是非单色串有 32−2=3032-2=30 条,被分成 30/5=630/5=6 组。所以 5∣25−25\mid 2^5-2。

一般地,aa 种珠子、长度 pp 的串有 apa^p 条,其中 aa 条是单色的,剩下 ap−aa^p-a 条按每 pp 条一组分组,因此 p∣ap−ap\mid a^p-a。这是同一个定理的纯组合证明。

欧拉定理

定理。 设 m=pqm=pq,p≠qp\ne q 为素数,gcd⁡(a,m)=1\gcd(a,m)=1,则

a(p−1)(q−1)≡1(modm).a^{(p-1)(q-1)}\equiv1\pmod m .

证明与费马小定理逐字相同,只需替换两处:

  • 用 gcd⁡(a,m)=1\gcd(a,m)=1 保证 aa 在模 mm 下可逆,从而由鸽巢原理得到 kk;
  • 用 ∣H∣=k|H|=k 与 Lagrange 定理,得到 k∣∣Zm∗∣=(p−1)(q−1)k\mid|\mathbb Z_m^*|=(p-1)(q-1)。

所以指数从 p−1p-1 变成 (p−1)(q−1)(p-1)(q-1),并不是新定理,而是同一证明中群的阶变了。这正是抽象的价值:两个看似不同的恒等式,在群的语言里是一个命题。

域与多项式根数(为后面铺垫)

域是带两个运算的集合 FF:(F,+)(F,+) 是阿贝尔群(单位元 00),(F∖{0},⋅)(F\setminus\{0\},\cdot) 也是阿贝尔群(单位元 11),且满足分配律 a(b+c)=ab+aca(b+c)=ab+ac。

定理(陈述)。 系数取自域 FF 的 dd 次多项式,在 FF 中最多有 dd 个根。

这解释了为什么「dd 次多项式最多 dd 个根」不是实数独有的性质,而是域的公理推出来的。后面的秘密共享方案正是利用这一点:把秘密藏在多项式的常数项里,用有限域上的求值点来分发份额。

本节结论

  • 群 = 封闭 + 结合 + 单位元 + 逆元;再加交换律就是阿贝尔群。
  • Zn∖{0}\mathbb Z_n\setminus\{0\} 在乘法下是群,当且仅当 nn 是素数;合数时 Zn∗\mathbb Z_n^* 才是群。
  • ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1,∣Zpq∗∣=(p−1)(q−1)|\mathbb Z_{pq}^*|=(p-1)(q-1)。
  • Lagrange 定理:∣H∣|H| 整除 ∣G∣|G|;证明靠左陪集的分割。
  • 费马小定理与欧拉定理是同一个证明,差别只在群的大小。
  • ap−2a^{p-2} 就是 aa 模 pp 的逆元。

理解检验

1. 证明:Zn∖{0}\mathbb Z_n\setminus\{0\} 在乘法下是群当且仅当 nn 是素数。

参考答案:nn 素数时,封闭性、结合律、单位元 11 都直接成立;对任意 a∈{1,…,n−1}a\in\{1,\dots,n-1\},gcd⁡(a,n)=1\gcd(a,n)=1,由扩欧引理存在 bb 使 ab≡1ab\equiv1,故每个元素可逆。nn 合数时,写 n=pqn=pq 且 1<p,q<n1<p,q<n,则 pp 与 nn 不互素,由引理的逆否命题 pp 不可逆,逆元公理失败。

2. 计算 ∣Zpq∗∣|\mathbb Z_{pq}^*|,并说明每一步计数的理由。

参考答案:候选集合是 1,…,pq−11,\dots,pq-1,共 pq−1pq-1 个。与 pqpq 不互素的数恰是被 pp 或 qq 整除的数。qq 的倍数有 q,2q,…,(p−1)qq,2q,\dots,(p-1)q 共 p−1p-1 个;pp 的倍数有 p,2p,…,(q−1)pp,2p,\dots,(q-1)p 共 q−1q-1 个;两者没有交集,因为 pqpq 不在范围内。故

∣Zpq∗∣=(pq−1)−(p−1)−(q−1)=(p−1)(q−1).|\mathbb Z_{pq}^*|=(pq-1)-(p-1)-(q-1)=(p-1)(q-1).

3. 证明每个左陪集 xHxH 与 HH 等势。

参考答案:考虑映射 φ:H→xH\varphi:H\to xH,φ(h)=xh\varphi(h)=xh。若 φ(h1)=φ(h2)\varphi(h_1)=\varphi(h_2),左乘 x−1x^{-1} 并由结合律得 (x−1x)h1=(x−1x)h2(x^{-1}x)h_1=(x^{-1}x)h_2,即 h1=h2h_1=h_2,所以是单射。按定义 xHxH 的每个元素都形如 xhxh,所以是满射。故 ∣xH∣=∣H∣|xH|=|H|。这里用到逆元、结合律、单位元三条公理。

4. 用 Lagrange 定理证明费马小定理,并指出「kk 存在」为什么需要鸽巢原理。

参考答案:设 kk 是最小的正整数使 ak≡1(modp)a^k\equiv1\pmod p。鸽巢原理给出 i<ji<j 使 ai≡aja^i\equiv a^j;因为 pp 素数且 p∤ap\nmid a,aa 可逆,两边乘 a−ia^{-i} 得 aj−i≡1a^{j-i}\equiv1,所以 k=j−ik=j-i 存在。令 H={a0,…,ak−1}H=\{a^0,\dots,a^{k-1}\},它对乘法封闭、含单位元、逆元为 ak−ma^{k-m},是 Zp∖{0}\mathbb Z_p\setminus\{0\} 的子群,且 ∣H∣=k|H|=k。由 Lagrange,k∣p−1k\mid p-1,写 p−1=ckp-1=ck,则 ap−1=(ak)c≡1a^{p-1}=(a^k)^c\equiv1。

5. 一个群有 66 个元素,能否有阶为 44 的子群?阶为 33 的呢?

参考答案:阶为 44 的子群不可能,因为 4∤64\nmid6,违反 Lagrange 定理。阶为 33 的子群可能,因为 3∣63\mid6(例如 Z7∖{0}\mathbb Z_7\setminus\{0\} 中的 {1,2,4}\{1,2,4\} 是阶 33 子群)。注意 Lagrange 定理只给出必要条件:d∣∣G∣d\mid|G| 不保证一定存在阶为 dd 的子群。

与前后课的关系

上一讲用扩展欧几里得解决「求逆元」;本讲把可逆元素组织成群,用 Lagrange 定理一次推出费马与欧拉定理。下一讲离开代数,进入线性规划,但对偶理论会在后面以「零和博弈」的形式重新出现——那是群论之外的另一种结构。再往后讲到密码学时,Zn∗\mathbb Z_n^* 的阶 (p−1)(q−1)(p-1)(q-1) 会成为 RSA 的全部秘密所在。

From "does an inverse exist?" to an abstract structure

The previous lecture asked: given aa and nn, is there a bb with ab≡1(modn)ab\equiv1\pmod n? The answer is decided by the greatest common divisor: such a bb exists exactly when gcd⁡(a,n)=1\gcd(a,n)=1, and it can be found with the extended Euclidean algorithm.

This lecture looks at the same fact from a different angle: promote invertibility into a whole algebraic structure. Once the language of groups is in place, several theorems that look unrelated — Lagrange's theorem, Fermat's little theorem, Euler's theorem — become different spellings of one proof.

Timeline

TimeTopic
0:00Recap: modular arithmetic and multiplicative inverses
2:09Definition of a group: closure, associativity, identity, inverse
6:19Examples: Z\mathbb Z under addition, Z\mathbb Z under multiplication (not a group), Q∖{0}\mathbb Q\setminus\{0\}
9:21Finite groups: Zn\mathbb Z_n under addition
10:28Zn∖{0}\mathbb Z_n\setminus\{0\} is a group under multiplication iff nn is prime
15:08The hidden group Zn∗\mathbb Z_n^*: elements coprime to nn
17:09Order of a group; $
22:15Definition of a subgroup
25:34Statement of Lagrange's theorem and an example
30:41Proof via left cosets
47:02Fermat's little theorem and its group-theoretic proof
56:20A combinatorial proof of Fermat's little theorem (necklaces)
1:03:31Euler's theorem
1:09:49Fields and the bound on the number of roots (groundwork for later cryptography)

Definition of a group

A group is a set GG with a binary operation ∗* satisfying four axioms:

  1. Closure: a,b∈G⇒a∗b∈Ga,b\in G\Rightarrow a*b\in G.
  2. Associativity: (a∗b)∗c=a∗(b∗c)(a*b)*c=a*(b*c) for all a,b,c∈Ga,b,c\in G.
  3. Identity: there is e∈Ge\in G with e∗a=a∗e=ae*a=a*e=a for all aa.
  4. Inverse: for every a∈Ga\in G there is a−1∈Ga^{-1}\in G with a−1∗a=a∗a−1=ea^{-1}*a=a*a^{-1}=e.

If in addition a∗b=b∗aa*b=b*a for all a,ba,b, the group is abelian (commutative).

The axioms do not state that the identity or the inverse is unique — both follow from the axioms, and proving that is one of the first exercises in group theory.

Examples and non-examples

Set and operationA group?Why
Z\mathbb Z under additionYesIdentity 00, inverse −a-a, commutative
Z\mathbb Z under multiplicationNo22 has inverse 1/2∉Z1/2\notin\mathbb Z; 00 has none
Q∖{0}\mathbb Q\setminus\{0\} under multiplicationYesInverse is the reciprocal, identity 11
Zn\mathbb Z_n under modular additionYesIdentity 00, inverse n−an-a
Zn∖{0}\mathbb Z_n\setminus\{0\} under modular multiplicationOnly when nn is primeSee below

Why Zn∖{0}\mathbb Z_n\setminus\{0\} is a group exactly when nn is prime

If nn is prime, it is a group. Closure follows from the definition of modular multiplication: a product of two residues, reduced again, is a residue. Associativity is inherited from integer multiplication. The identity is 11. The only nontrivial axiom is the inverse: by the lemma from last lecture, aa has an inverse whenever gcd⁡(a,n)=1\gcd(a,n)=1. For prime nn and a∈{1,…,n−1}a\in\{1,\dots,n-1\} we have gcd⁡(a,n)=1\gcd(a,n)=1, so every nonzero element is invertible.

If nn is composite, it is not a group. Write n=pqn=pq with p,q>1p,q>1. Then p∈Zn∖{0}p\in\mathbb Z_n\setminus\{0\} and gcd⁡(p,n)=p≠1\gcd(p,n)=p\ne1. By the contrapositive of the same lemma, pp has no multiplicative inverse, so the inverse axiom fails.

The lesson: being a group depends not only on the set but on the operation attached to it.

The group hiding inside

When nn is composite, Zn∖{0}\mathbb Z_n\setminus\{0\} is not a group, but a subset of it is:

Zn∗={a∈Zn:gcd⁡(a,n)=1}.\mathbb Z_n^*=\{a\in\mathbb Z_n:\gcd(a,n)=1\}.

It is closed under multiplication (a product of two numbers coprime to nn is coprime to nn), has identity 11, and every element is invertible by the lemma; the inverse is also coprime to nn. So Zn∗\mathbb Z_n^* is a group. It will reappear when we discuss RSA.

Order, and two counts

The order of a finite group GG, written ∣G∣|G|, is its number of elements.

  • ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1 for prime pp.
  • ∣Zpq∗∣=(p−1)(q−1)|\mathbb Z_{pq}^*|=(p-1)(q-1) for distinct primes p,qp,q.

The second count is inclusion–exclusion. Start with the pq−1pq-1 numbers 1,…,pq−11,\dots,pq-1 and remove those not coprime to pqpq, i.e. multiples of pp or of qq. The multiples of qq are q,2q,…,(p−1)qq,2q,\dots,(p-1)q, giving p−1p-1 of them; the multiples of pp are p,2p,…,(q−1)pp,2p,\dots,(q-1)p, giving q−1q-1. There is no overlap, because pqpq is out of range. Hence

∣Zpq∗∣=(pq−1)−(p−1)−(q−1)=pq−p−q+1=(p−1)(q−1).|\mathbb Z_{pq}^*|=(pq-1)-(p-1)-(q-1)=pq-p-q+1=(p-1)(q-1).

This number is Euler's totient φ(pq)\varphi(pq).

Subgroups

Let H⊆GH\subseteq G. If HH is itself a group under the same operation, it is a subgroup of GG.

The key is a stronger closure: for a,b∈Ha,b\in H we need a∗b∈Ha*b\in H, not merely a∗b∈Ga*b\in G (the latter is automatic). Likewise a−1a^{-1} must lie in HH. Inside HH you never have to step outside HH to multiply or invert.

Example. Let G=Z7∖{0}G=\mathbb Z_7\setminus\{0\}, so ∣G∣=6|G|=6, and take H={1,2,4}H=\{1,2,4\}. Check: 1⋅2=21\cdot2=2, 1⋅4=41\cdot4=4, 2⋅4=8≡12\cdot4=8\equiv1, all in HH; and 2−1=42^{-1}=4, 4−1=24^{-1}=2, 1−1=11^{-1}=1.

A cleaner way to see it: HH is exactly the set of powers of 22 modulo 77:

20=1,21=2,22=4,23=8≡1.2^0=1,\qquad 2^1=2,\qquad 2^2=4,\qquad 2^3=8\equiv1.

Multiplying powers adds exponents, so closure is automatic; 23=12^3=1 supplies the inverses (21⋅22=12^1\cdot2^2=1). This is the standard way to build a subgroup: take all powers of one element.

Lagrange's theorem

Theorem. If GG is a finite group and H≤GH\le G is a subgroup, then ∣H∣|H| divides ∣G∣|G|.

Its power is out of proportion to its hypotheses: from four axioms it constrains which subgroup sizes can exist at all. If ∣G∣=6|G|=6, a subgroup can only have order 1,2,31,2,3 or 66; orders 44 or 55 are impossible.

Left cosets

For x∈Gx\in G, define

xH={xh:h∈H}.xH=\{xh:h\in H\}.

This is HH translated by xx, called a left coset. If x∈Hx\in H then xH=HxH=H; otherwise it is a shifted copy of HH.

The two-step proof

Plan. Write GG as a disjoint union of left cosets,

G=x1H  ∪˙  x2H  ∪˙⋯∪˙  xkH,G=x_1H\;\dot\cup\;x_2H\;\dot\cup\cdots\dot\cup\;x_kH ,

with every coset the same size as HH. Then ∣G∣=k∣H∣|G|=k|H|, which gives divisibility.

The cosets are produced greedily: pick any uncovered element as x1x_1 and remove x1Hx_1H; pick any still-uncovered element as x2x_2 and remove x2Hx_2H; continue.

Step 1: every coset has the same size as HH. Consider h↦xhh\mapsto xh. It is injective: if xh1=xh2xh_1=xh_2, left-multiply by x−1x^{-1} and use associativity,

x−1(xh1)=x−1(xh2)  ⟹  (x−1x)h1=(x−1x)h2  ⟹  eh1=eh2  ⟹  h1=h2.x^{-1}(xh_1)=x^{-1}(xh_2) \;\Longrightarrow\; (x^{-1}x)h_1=(x^{-1}x)h_2 \;\Longrightarrow\; eh_1=eh_2 \;\Longrightarrow\; h_1=h_2 .

It is surjective by definition of xHxH. Hence ∣xH∣=∣H∣|xH|=|H|. This argument uses the inverse, associativity and the identity — all of the group axioms appear here.

Step 2: distinct cosets are disjoint. Suppose xiHx_iH and xjHx_jH share an element, so

xih1=xjh2x_ih_1=x_jh_2

for some h1,h2∈Hh_1,h_2\in H. Right-multiply by h2−1h_2^{-1}:

xj=xih1h2−1.x_j=x_ih_1h_2^{-1}.

Since HH is a subgroup, h2−1∈Hh_2^{-1}\in H and, by closure, h1h2−1∈Hh_1h_2^{-1}\in H. Therefore xj∈xiHx_j\in x_iH.

But xjx_j was chosen as an element not yet covered, while xiHx_iH had already been removed and covers xjx_j — a contradiction. So distinct cosets cannot intersect.

Together: GG is partitioned into kk disjoint blocks of size ∣H∣|H|, so ∣G∣=k∣H∣|G|=k|H| and ∣H∣∣∣G∣|H|\mid|G|.

Fermat's little theorem

Theorem. If pp is prime and p∤ap\nmid a, then

ap−1≡1(modp).a^{p-1}\equiv1\pmod p .

Corollary. ap−2a^{p-2} is the multiplicative inverse of aa mod pp, since ap−2⋅a=ap−1≡1a^{p-2}\cdot a=a^{p-1}\equiv1. This gives a second way to invert, by exponentiation instead of the extended Euclidean algorithm.

Proof

Let kk be the smallest positive integer with ak≡1(modp)a^k\equiv1\pmod p.

kk exists. Consider the residues of a1,a2,a3,…a^1,a^2,a^3,\dots modulo pp. There are only pp possible residues but infinitely many powers, so by the pigeonhole principle there are i<ji<j with

ai≡aj(modp).a^i\equiv a^j\pmod p .

Because pp is prime and p∤ap\nmid a, aa is invertible; multiply by a−ia^{-i}:

aj−i≡1(modp).a^{j-i}\equiv1\pmod p .

So k=j−ik=j-i works. The invertibility of aa — which comes from pp being prime — is what makes this step valid.

The powers form a subgroup. Let H={a0,a1,…,ak−1}H=\{a^0,a^1,\dots,a^{k-1}\}. It is closed under multiplication (add exponents, reduce modulo kk), contains the identity a0=1a^0=1, and the inverse of ama^m is ak−ma^{k-m}. Hence HH is a subgroup with ∣H∣=k|H|=k, since minimality of kk makes a0,…,ak−1a^0,\dots,a^{k-1} distinct.

Finish with Lagrange. H≤Zp∖{0}H\le\mathbb Z_p\setminus\{0\} and ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1, so k∣p−1k\mid p-1. Write p−1=ckp-1=ck. Then

ap−1=ack=(ak)c≡1c≡1(modp).a^{p-1}=a^{ck}=(a^k)^c\equiv1^c\equiv1\pmod p .

Only two ingredients are used: invertibility of aa (so kk exists) and Lagrange's theorem (so k∣p−1k\mid p-1).

A second proof: counting necklaces

Fermat's little theorem is equivalent to p∣ap−ap\mid a^p-a (multiply both sides by aa). Take a=2a=2, p=5p=5.

String 55 beads, each red or blue, and join the ends to form a necklace; rotations count as the same necklace. There are 25=322^5=32 strings. A non-monochromatic necklace comes from exactly 55 different strings, because 55 is prime and a non-constant string has no nontrivial rotational symmetry. The only monochromatic necklaces are all-red and all-blue, each coming from a single string. So 32−2=3032-2=30 strings split into 30/5=630/5=6 groups, proving 5∣25−25\mid2^5-2.

In general, with aa bead colours and length pp, there are apa^p strings, aa of them monochromatic, and the remaining ap−aa^p-a group into blocks of pp. Hence p∣ap−ap\mid a^p-a — the same theorem, proved combinatorially.

Euler's theorem

Theorem. Let m=pqm=pq with distinct primes p,qp,q, and suppose gcd⁡(a,m)=1\gcd(a,m)=1. Then

a(p−1)(q−1)≡1(modm).a^{(p-1)(q-1)}\equiv1\pmod m .

The proof is the same as for Fermat's little theorem with two substitutions:

  • gcd⁡(a,m)=1\gcd(a,m)=1 makes aa invertible mod mm, so the pigeonhole argument produces kk;
  • Lagrange applied to HH gives k∣∣Zm∗∣=(p−1)(q−1)k\mid|\mathbb Z_m^*|=(p-1)(q-1).

The exponent changes from p−1p-1 to (p−1)(q−1)(p-1)(q-1) not because the theorem is new, but because the order of the ambient group changed. That is the payoff of abstraction: two seemingly different identities are one statement in the language of groups.

Fields and the number of roots (groundwork)

A field is a set FF with two operations such that (F,+)(F,+) is an abelian group with identity 00, (F∖{0},⋅)(F\setminus\{0\},\cdot) is an abelian group with identity 11, and distributivity a(b+c)=ab+aca(b+c)=ab+ac holds.

Theorem (stated). A polynomial of degree dd with coefficients in a field FF has at most dd roots in FF.

So "a degree-dd polynomial has at most dd roots" is not special to the reals; it follows from the field axioms. The secret-sharing scheme discussed later exploits exactly this: hide the secret in the constant term and hand out evaluations at points of a finite field.

What this lecture establishes

  • A group is closure, associativity, identity and inverse; adding commutativity gives an abelian group.
  • Zn∖{0}\mathbb Z_n\setminus\{0\} is a group under multiplication iff nn is prime; for composite nn the group is Zn∗\mathbb Z_n^*.
  • ∣Zp∖{0}∣=p−1|\mathbb Z_p\setminus\{0\}|=p-1 and ∣Zpq∗∣=(p−1)(q−1)|\mathbb Z_{pq}^*|=(p-1)(q-1).
  • Lagrange's theorem: ∣H∣|H| divides ∣G∣|G|, proved by partitioning into left cosets.
  • Fermat's little theorem and Euler's theorem are one proof; only the group order differs.
  • ap−2a^{p-2} is the inverse of aa modulo pp.

Comprehension check

1. Prove that Zn∖{0}\mathbb Z_n\setminus\{0\} is a group under multiplication if and only if nn is prime.

Reference answer: If nn is prime, closure, associativity and the identity 11 are immediate; for any a∈{1,…,n−1}a\in\{1,\dots,n-1\} we have gcd⁡(a,n)=1\gcd(a,n)=1, so the extended-Euclid lemma gives bb with ab≡1ab\equiv1, hence every element is invertible. If nn is composite, write n=pqn=pq with 1<p,q<n1<p,q<n; then pp is not coprime to nn, so by the contrapositive of the lemma pp is not invertible and the inverse axiom fails.

2. Compute ∣Zpq∗∣|\mathbb Z_{pq}^*| and justify each counting step.

Reference answer: The candidates are 1,…,pq−11,\dots,pq-1, giving pq−1pq-1 numbers. Those not coprime to pqpq are precisely the multiples of pp or of qq. The multiples of qq are q,2q,…,(p−1)qq,2q,\dots,(p-1)q, so p−1p-1 of them; the multiples of pp are p,2p,…,(q−1)pp,2p,\dots,(q-1)p, so q−1q-1. They are disjoint because pqpq is out of range. Hence

∣Zpq∗∣=(pq−1)−(p−1)−(q−1)=(p−1)(q−1).|\mathbb Z_{pq}^*|=(pq-1)-(p-1)-(q-1)=(p-1)(q-1).

3. Prove that every left coset xHxH has the same cardinality as HH.

Reference answer: Consider φ:H→xH\varphi:H\to xH, φ(h)=xh\varphi(h)=xh. If φ(h1)=φ(h2)\varphi(h_1)=\varphi(h_2), left-multiplying by x−1x^{-1} and using associativity gives (x−1x)h1=(x−1x)h2(x^{-1}x)h_1=(x^{-1}x)h_2, i.e. h1=h2h_1=h_2; so φ\varphi is injective. It is surjective by the definition of xHxH. Hence ∣xH∣=∣H∣|xH|=|H|. The proof uses the inverse, associativity and the identity.

4. Prove Fermat's little theorem using Lagrange's theorem, and explain why the existence of kk needs the pigeonhole principle.

Reference answer: Let kk be the least positive integer with ak≡1(modp)a^k\equiv1\pmod p. Pigeonhole gives i<ji<j with ai≡aja^i\equiv a^j; since pp is prime and p∤ap\nmid a, aa is invertible, so multiplying by a−ia^{-i} yields aj−i≡1a^{j-i}\equiv1, and k=j−ik=j-i exists. Let H={a0,…,ak−1}H=\{a^0,\dots,a^{k-1}\}; it is closed under multiplication, contains the identity and has inverses ak−ma^{k-m}, so it is a subgroup of Zp∖{0}\mathbb Z_p\setminus\{0\} of order kk. Lagrange gives k∣p−1k\mid p-1; writing p−1=ckp-1=ck gives ap−1=(ak)c≡1a^{p-1}=(a^k)^c\equiv1.

5. A group has 66 elements. Can it have a subgroup of order 44? Of order 33?

Reference answer: No subgroup of order 44, since 4∤64\nmid6, contradicting Lagrange. A subgroup of order 33 is possible since 3∣63\mid6 (for instance {1,2,4}\{1,2,4\} inside Z7∖{0}\mathbb Z_7\setminus\{0\}). Lagrange gives only a necessary condition: d∣∣G∣d\mid|G| does not guarantee that a subgroup of order dd exists.

Relation to neighbouring lectures

The previous lecture solved "find the inverse" with the extended Euclidean algorithm; this lecture organises the invertible elements into a group and derives Fermat and Euler from Lagrange's theorem in one stroke. The next lecture leaves algebra for linear programming, but duality will return in the guise of zero-sum games — another structure altogether. Later, in cryptography, the order (p−1)(q−1)(p-1)(q-1) of Zn∗\mathbb Z_n^* becomes the whole secret behind RSA.

来源