# 模算术

模算术是关于余数的算术：若两个整数之差是某个固定正整数的倍数，则这两个整数在该正整数下被视为等价，即同余，这个固定的正整数称为模数。卡尔·弗里德里希·高斯（Carl Friedrich Gauss）在1801年的《算术研究》（*Disquisitiones Arithmeticae*）中引入了同余的记号体系，奠定了今天提出余数问题的框架，而这一学科如今是公钥密码学、计算机代数以及数论诸多分支的基础。<sup>[1](https://www.sciencedirect.com/science/article/pii/S0315086008000670)</sup><sup> • </sup><sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | \( a \equiv b \pmod{m} \) 表示 \( m \) 整除 \( a - b \)；等价地说，\( a \) 与 \( b \) 除以 \( m \) 所得余数相同<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup> |
| 起源 | 由高斯在《算术研究》（1801）中形式化并系统化；欧拉（Euler）曾于1761年研究幂模 \( n \) 的余数<sup>[1](https://www.sciencedirect.com/science/article/pii/S0315086008000670)</sup><sup> • </sup><sup>[3](https://mathshistory.st-andrews.ac.uk/HistTopics/Development_group_theory/)</sup> |
| 结构 | 模 \( m \) 的 \( m \) 个剩余类在加法下构成一个阿贝尔群，在加法与乘法下构成一个环<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup> |
| 单位 | \( a \) 模 \( m \) 有乘法逆元，当且仅当 \( \gcd(a, m) = 1 \)<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup> |
| 关键定理 | 费马小定理：若 \( p \) 为素数且 \( p \nmid a \)，则 \( a^{p-1} \equiv 1 \pmod{p} \)<sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup> |
| 密码学应用 | RSA 建立在模合数 \( N = P \cdot Q \) 的模算术之上；ML-KEM（FIPS 203，2024）在素数 \( q = 3329 \) 上进行精确的模算术<sup>[6](https://pi.math.cornell.edu/~mec/2003-2004/cryptography/RSA/RSA.html)</sup><sup> • </sup><sup>[7](https://www.nist.gov/document/formal-speci-cations-certi-able-cryptography)</sup> |

## 同余与剩余类

同余式 \( a \equiv b \pmod{m} \) 可写作 \( a = b + mk \)（\( k \) 为某整数），其中 \( m \) 称为模数。若差 \( a - b \) 不能被 \( m \) 整除，则称这两个整数模 \( m \) 不同余。同余式表达的是：\( a \) 与 \( b \) 除以 \( m \) 所得余数完全相同。<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup>

模固定 \( m \) 的同余是一种等价关系：它具有自反性、对称性和传递性。因此它把整数划分为 \( m \) 个互不相交的剩余类，并且每个整数模 \( m \) 恰与 \( 0, 1, \dots, m-1 \) 中的一个数同余，这些数构成一组代表元。从每个剩余类中各取一个数，所得的 \( m \) 个整数组成的集合称为模 \( m \) 的一个完全剩余系。<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup>

**剩余类上的运算。** 模同一数的同余式可以像普通等式一样相加、相减、相乘：由 \( a \equiv b \) 与 \( c \equiv d \) 可得 \( a \pm c \equiv b \pm d \) 以及 \( ac \equiv bd \)（均模 \( m \)）。两边可以同乘一个整数，也可以同除以一个公约数，只要该公约数与模数互素。<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup> 具体例子：\( 6 + 7 = 1 \pmod{12} \)，\( 3 \times 20 = 10 \pmod{50} \)，以及 \( 38 = 3 \pmod{5} \)，因为 \( 38 = 7 \times 5 + 3 \)。<sup>[8](https://crypto.stanford.edu/pbc/notes/numbertheory/arith.html)</sup>

剩余类之间没有大小概念：说 \( 0 < 4 \pmod{8} \) 毫无意义，因为两边同加4便得到 \( 4 < 0 \pmod{8} \)。模 \( n \) 的整数被设想为分布在一个圆周上，如同模12的钟面，而不是在数轴上。<sup>[8](https://crypto.stanford.edu/pbc/notes/numbertheory/arith.html)</sup>

## 代数结构

模 \( m \) 的剩余类在加法下构成一个 \( m \) 阶阿贝尔群，以 \( m \) 的倍数所在的类为零元素；在加法、减法与乘法下构成一个环。<sup>[2](https://encyclopediaofmath.org/wiki/Congruence)</sup> 用现代记号，这个环记作 \( \mathbb{Z}/n\mathbb{Z} \)，即整数环对由 \( n \) 生成的理想的商。<sup>[9](https://www.cs.drexel.edu/~johnsojr/wi00/ca1/lectures/jan5.html)</sup>

**单位与零因子。** 整数 \( a \) 是模 \( m \) 的单位，即它有乘法逆元，当且仅当 \( a \) 与 \( m \) 互素；其逆元可通过运行欧几里得算法求出整数 \( x \) 与 \( y \) 使 \( ax + my = 1 \)，此时 \( x \) 即为 \( a \) 的逆元。<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup> 若非零剩余类与另一个非零剩余类相乘得零，则称其为零因子；\( a \) 是模 \( m \) 的零因子，当且仅当 \( 1 < \gcd(a, m) < m \)。<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup> 例如模6时，\( \bar{2} \cdot \bar{3} = \bar{0} \)，因此任意消去律不成立：\( \bar{2} \cdot \bar{3} = \bar{2} \cdot \bar{0} \)，但 \( \bar{3} \neq \bar{0} \)。<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup> 一般的消去法则是：\( ax \equiv ay \pmod{m} \) 等价于 \( x \equiv y \pmod{m/d} \)，其中 \( d = \gcd(a, m) \)。<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup>

当模数 \( p \) 为素数时，每个非零剩余类都是单位，因此 \( \mathbb{Z}/p\mathbb{Z} \) 是一个域，而 \( (\mathbb{Z}/p)^{\times} \) 有 \( p - 1 \) 个元素。<sup>[4](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)</sup><sup> • </sup><sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup> 模任意 \( n \) 的单位在乘法下构成一个群，记作 \( (\mathbb{Z}/n)^{\times} \)。<sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup>

**经典定理。** 费马小定理指出，对素数 \( p \)，有 \( a^p \equiv a \pmod{p} \)；当 \( p \) 不整除 \( a \) 时，有 \( a^{p-1} \equiv 1 \pmod{p} \)。<sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup> 中国剩余定理指出，若 \( a \) 与 \( b \) 互素，则任意一对同余式 \( z \equiv x \pmod{a} \) 与 \( z \equiv y \pmod{b} \) 都有解 \( z \)，且该解模 \( ab \) 唯一。<sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup> 同余式还给出一种廉价的整数根检验法：若一个整系数多项式有整数根，则它对每个 \( n \) 都有模 \( n \) 的根，因此若它在某个 \( n \) 下无根，便可排除整数根；而且与整数根不同，模 \( n \) 的根可以通过逐一尝试有限多种可能来找到。例如方程 \( x^2 = -1 \) 模2和模5有解，但模3和模7无解。<sup>[5](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)</sup>

## 历史

从13世纪到18世纪，余数问题在计算、代数与趣味数学的书籍中流传，针对具体情形有许多解法。巴歇·德·梅齐里亚克（Bachet de Méziriac）于1624年首次将这些方法与欧几里得算法及丢番图分析联系起来；欧拉独立地重新发现了类似方法，冯·克劳斯贝格（von Clausberg）用最大公约数程序将这些途径系统化，欧拉与拉格朗日（Lagrange）则发展了连分数方法。随后高斯在《算术研究》中提出了同余的记号体系，创建了今天提出这些问题的模算术框架。<sup>[1](https://www.sciencedirect.com/science/article/pii/S0315086008000670)</sup>

欧拉早在1761年就研究过模算术，考察一个数的幂模 \( n \) 的余数，用现代术语说，他的工作中包含了将一个阿贝尔群分解为子群的陪集。高斯在1801年将此大大推进：他在模算术方面的工作实质上是一套相当完整的阿贝尔群理论，包括元素的阶，以及循环群对其阶的每个因子都有子群的证明。他还研究了二元二次型 \( ax^2 + 2bxy + cy^2 \)，将它们划分为类，在这些类上定义了合成运算，并证明了该合成运算的结合律。<sup>[3](https://mathshistory.st-andrews.ac.uk/HistTopics/Development_group_theory/)</sup> 自1801年以拉丁文出版以来，《算术研究》一直是数论发展的源泉。<sup>[10](https://link.springer.com/book/10.1007/978-1-4939-7560-0)</sup>

## 密码学中的应用

公钥密码学建立在模算术、素数以及分解的困难性之上。在RSA中，接收方选取两个大的秘密素数 \( P \) 与 \( Q \)，公开模数 \( N = P \cdot Q \) 以及与 \( Z = (P-1)(Q-1) \) 互素的加密指数 \( E \)，并保密满足 \( E \cdot D \equiv 1 \pmod{Z} \) 的解密指数 \( D \)，后者用欧几里得算法求得。加密与解密都是模幂运算。<sup>[6](https://pi.math.cornell.edu/~mec/2003-2004/cryptography/RSA/RSA.html)</sup> RSA的安全性依赖于模算术中计算 \( e \) 次根的困难性，这与离散对数问题相关。<sup>[11](https://www.cs.toronto.edu/~david/course-notes/csc110-111/08-cryptography/04-rsa-cryptosystem.html)</sup>

模算术在最新的标准中依然居于核心地位。ML-KEM是一种基于模格的密钥封装机制，于2024年8月被标准化为FIPS 203，被认为能抵抗量子对手；它的所有算术都在素数 \( q = 3329 \) 下的域元素与多项式环元素上进行，使用数论变换蝶形运算进行精确的模算术。<sup>[7](https://www.nist.gov/document/formal-speci-cations-certi-able-cryptography)</sup><sup> • </sup><sup>[12](https://arxiv.org/abs/2609.28904)</sup> NIST于2024年8月发布了首批三项后量子标准，并在第四轮评估之后选定HQC作为唯一拟额外予以标准化的密钥建立算法，扩充了其密钥建立组合。<sup>[13](https://www.nist.gov/publications/status-report-fourth-round-nist-post-quantum-cryptography-standardization-process)</sup>

模算术也出现在校验和等较轻量的场景中，模加校验和算法在错误检测强度与计算开销之间进行权衡。<sup>[14](https://arxiv.org/abs/2302.13432)</sup>

## References

1. [Maarten Bullynck (2009). Modular arithmetic before C.F. Gauss: Systematizations and discussions on remainder problems in 18th-century Germany. Historia Mathematica 36(1), 48–72.](https://www.sciencedirect.com/science/article/pii/S0315086008000670)
2. [Congruence, Encyclopedia of Mathematics.](https://encyclopediaofmath.org/wiki/Congruence)
3. [Development of Group Theory, MacTutor History of Mathematics.](https://mathshistory.st-andrews.ac.uk/HistTopics/Development_group_theory/)
4. [Evan Dummit (2022). Number Theory (part 2): Modular Arithmetic in Z. Northeastern University course notes.](https://dummit.cos.northeastern.edu/teaching_sp22_3527/numthy_2_modular_arithmetic_v3.00.pdf)
5. [MATH 417: Introduction to abstract algebra — 9/9: Modular arithmetic, University of Illinois.](https://itamar.web.illinois.edu/Teaching/417_FW26/Notes/node-9-9-Modular-arithmetic.html)
6. [Primes, Modular Arithmetic and Public Key Cryptography II, Cornell Mathematics.](https://pi.math.cornell.edu/~mec/2003-2004/cryptography/RSA/RSA.html)
7. [Formal Specifications for Certifiable Cryptography, NIST.](https://www.nist.gov/document/formal-speci-cations-certi-able-cryptography)
8. [Number Theory — Modular Arithmetic, Stanford crypto notes.](https://crypto.stanford.edu/pbc/notes/numbertheory/arith.html)
9. [Lecture 1: The Integers, Modular Arithmetic, and the Euclidean Algorithm, Drexel University.](https://www.cs.drexel.edu/~johnsojr/wi00/ca1/lectures/jan5.html)
10. [Disquisitiones Arithmeticae, Springer Nature Link.](https://link.springer.com/book/10.1007/978-1-4939-7560-0)
11. [The RSA Cryptosystem, University of Toronto CSC110/111 course notes.](https://www.cs.toronto.edu/~david/course-notes/csc110-111/08-cryptography/04-rsa-cryptosystem.html)
12. [Implementation and Evaluation of NTT Arithmetic for ML-KEM on a CGLA, arXiv.](https://arxiv.org/abs/2609.28904)
13. [Status Report on the Fourth Round of the NIST Post-Quantum Cryptography Standardization Process (NIST IR 8545), 2025.](https://www.nist.gov/publications/status-report-fourth-round-nist-post-quantum-cryptography-standardization-process)
14. [Large-Block Modular Addition Checksum Algorithms, arXiv.](https://arxiv.org/abs/2302.13432)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Elementary number theory › Congruences and modular arithmetic

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/modular-arithmetic

English original: https://www.edgepedia.org/modular-arithmetic
