# 欧几里得除法

**欧几里得除法**（Euclidean division）是一条定理，也称除法算法，它断言：用一个非零整数除另一个整数，会产生唯一的商和唯一的余数，且余数小于除数。对整数 \(a \neq 0\) 与 \(b\)，存在唯一的整数 \(q\) 和 \(r\)，使得

\[ b = aq + r, \quad 0 \le r < a. \]

这里 \(q\) 是商，\(r\) 是余数；两个子运算写作 \(b \operatorname{div} a = q\) 与 \(b \bmod a = r\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>。例如，\(3 \nmid 14\)，但 \(14 = 3 \cdot 4 + 2\)，所以用 3 除 14，得 4 余 2<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>。

| 关键事实 | 细节 |
|---|---|
| 陈述 | 对 \(a \neq 0\)，存在唯一的 \(q, r\)，满足 \(b = aq + r\) 且 \(0 \le r < a\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> |
| 负除数 | 对任意非零除数 \(m\)，这一界推广为 \(0 \le r < \|m\|\)<sup>[2](https://cs.yale.edu/homes/aspnes/pinewiki/NumberTheory.html)</sup> |
| 证明方法 | 取非负值 \(n - qd\) 所成集合的最小元；若它至少为 \(d\)，减去 \(d\) 便得到更小的元素，矛盾<sup>[3](https://math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)</sup> |
| 商作为下取整 | 除数为正时，\(q = \lfloor b/a \rfloor\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> |
| 代数推广 | 欧几里得整环是带有一个欧几里得范数 \(\nu\) 的整环，其中 \(a = qb + r\)，且 \(\nu(r) < \nu(b)\) 或 \(r = 0\)<sup>[4](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)</sup> |
| 标准例子 | \(\mathbb{Z}\) 配以 \(\nu(a) = \|a\|\)；\(F[x]\) 配以次数函数；高斯整数 \(\mathbb{Z}[i]\) 配以 \(\sigma(a+bi) = a^2 + b^2\)<sup>[5](https://ocw.mit.edu/courses/res-18-012-algebra-ii-student-notes-spring-2022/mit18_702s22_full_lec.pdf)</sup> |
| 推论 | 每个欧几里得整环都是主理想整环，但并非每个主理想整环都是欧几里得整环<sup>[6](https://people.math.binghamton.edu/dikran/525/summary.html)</sup> |

## 定理及其证明

商与余数的存在性和唯一性可由良序论证证明。对 \(n \in \mathbb{Z}\) 与正除数 \(d\)，考虑所有形如 \(n - qd\) 的非负整数，其中 \(q \in \mathbb{Z}\)。该集合非空，故有最小元 \(r\)，记作 \(r = n - qd\)。若 \(r \ge d\)，则 \(n - (q+1)d = r - d\) 是该集合中更小的非负元素，矛盾；因此 \(0 \le r < d\)<sup>[3](https://math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)</sup>。同样的最小元论证出现在标准的离散数学处理中：集合 \(R = \{ r \mid r \ge 0,\ \exists q: n = qm + r \}\) 包含 \(n\)，因而有最小值<sup>[2](https://cs.yale.edu/homes/aspnes/pinewiki/NumberTheory.html)</sup>。

**唯一性**由大小界推出。假设 \(b = aq_1 + r_1 = aq_2 + r_2\)，且两个余数都在 \([0, a)\) 中。那么 \(a \mid r_2 - r_1\)，但若两个余数不同，则 \(0 < r_2 - r_1 < a\)，而该范围内 \(a\) 的唯一倍数是 0；所以 \(r_2 = r_1\)，于是 \(a(q_1 - q_2) = 0\) 迫使 \(q_1 = q_2\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>。

当除数为正时，商恰好是实值商的下取整：由 \(aq \le b < a(q+1)\) 可得 \(q = \lfloor b/a \rfloor\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>。当除数为负时，余数条件变为 \(0 \le r < \|m\|\)，商也相应调整<sup>[2](https://cs.yale.edu/homes/aspnes/pinewiki/NumberTheory.html)</sup>。

## 余数与同余

欧几里得除法是模算术的基础。两个整数 \(a\) 与 \(b\) 模正整数 \(m\) 同余，写作 \(a \equiv b \bmod m\)，当且仅当 \(a \bmod m = b \bmod m\)；证明方法是把两数都除以 \(m\)，比较余数 \(r_a\) 与 \(r_b\)；二者必然相等，因为它们的差是 \(m\) 的倍数，且严格介于 \(-m\) 与 \(m\) 之间<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>。说 \(n \bmod m = 0\)，等同于说 \(m\) 整除 \(n\)<sup>[2](https://cs.yale.edu/homes/aspnes/pinewiki/NumberTheory.html)</sup>。

带余除法也为欧几里得算法提供基础；该算法通过反复除法计算最大公约数：作除法，取余数，重复直到余数为零<sup>[7](https://www.geschichte-der-informatik.de/articles/the_algorithm_as_a_concept/)</sup>。从历史上看，顺序正好相反：欧几里得（Euclid）的《几何原本》（第七至第九卷，约写于公元前 300 年）把该算法表述为互减（辗转相减法），并且可以证明，欧几里得算法本质上等价于除法算法与贝祖（Bézout）等式<sup>[8](https://arxiv.org/abs/0902.2465)</sup>。

## 欧几里得整环

整数上的这一定理可推广到抽象环。整环 \(R\) 上的欧几里得范数是一个函数 \(\nu\)，使得对非零 \(a, b\) 有 \(\nu(a) \le \nu(ab)\)，并且对所有非零 \(a, b\)，存在 \(q, r \in R\)，满足 \(a = qb + r\)，且 \(\nu(r) < \nu(b)\) 或 \(r = 0\)；第二条性质就是除法算法。欧几里得整环是带有这种范数的整环<sup>[4](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)</sup>。等价地说，它是一个这样的整环：其中带余除法可行，且余数的大小小于除数<sup>[5](https://ocw.mit.edu/courses/res-18-012-algebra-ii-student-notes-spring-2022/mit18_702s22_full_lec.pdf)</sup>。

标准例子有：

- 整数 \(\mathbb{Z}\)，配以 \(\nu(a) = \|a\|\)<sup>[4](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)</sup>。
- 域 \(F\) 上的每个多项式环 \(F[x]\)，以次数函数为范数（规定 0 的次数为 0）；多项式长除法是具体算法，产生 \(p(x) = a(x)d(x) + b(x)\)，其中 \(b = 0\) 或 \(\deg b < \deg d\)<sup>[4](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)</sup><sup> • </sup><sup>[9](https://web.math.utk.edu/~dcartwr1/iaawa/section-poly-division-algorithm.html/section-euclidean-domains.html)</sup>。
- 高斯整数 \(\mathbb{Z}[i]\)，配以 \(\sigma(a + bi) = a^2 + b^2\)；除法性质由几何推出，因为 \(b\) 的倍数构成正方形格，所以 \(a\) 可以移动到某个倍数的半个格距以内，从而 \(\sigma(r) \le \tfrac{1}{2}\sigma(b)\)<sup>[5](https://ocw.mit.edu/courses/res-18-012-algebra-ii-student-notes-spring-2022/mit18_702s22_full_lec.pdf)</sup>。

在任何欧几里得整环中，范数在非零元素上的最小值是 \(\nu(1)\)，且元素 \(u\) 满足 \(\nu(u) = \nu(1)\) 当且仅当 \(u\) 是单位；在 \(F[x]\) 中，单位恰好是非零常数多项式<sup>[4](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)</sup>。

**在环的层级中的位置。** 每个欧几里得整环都是主理想整环：一个理想中范数最小的元素必定整除其他所有元素，因为作除法会留下一个余数；若它不为零，就会更小，且仍属于该理想<sup>[6](https://people.math.binghamton.edu/dikran/525/summary.html)</sup><sup> • </sup><sup>[10](https://andrew.cmu.edu/~dennisc2/alg-primer.pdf)</sup>。逆命题不成立：\(\mathbb{Z}\left[\tfrac{1+\sqrt{-19}}{2}\right]\) 是一个主理想整环，但不是欧几里得整环<sup>[6](https://people.math.binghamton.edu/dikran/525/summary.html)</sup>；近期工作从实闭域构造出更多非欧几里得的主理想整环族<sup>[11](https://arxiv.org/abs/2503.17464)</sup>。由于每个主理想整环都是唯一分解整环，\(\mathbb{Z}\) 中的唯一分解最终依赖于除法算法在那里成立<sup>[5](https://ocw.mit.edu/courses/res-18-012-algebra-ii-student-notes-spring-2022/mit18_702s22_full_lec.pdf)</sup>。

## 计算中的带余除法

编程语言实现了欧几里得除法的两个输出，但当操作数为负时，各语言并不一致，因为数学定理只有在选定一种舍入约定之后才能确定余数。C++ 把商向零截断，丢弃小数部分，因此余数可以为负；在 C++11 之前，舍入方向由实现定义<sup>[12](https://en.cppreference.com/cpp/language/operator_arithmetic)</sup>。Python 的向下取整除法 `//` 应用下取整函数，其 `%` 运算符总是返回与第二操作数同号的结果，并且恒等式 `x == (x//y)*y + (x%y)` 始终成立<sup>[13](https://github.com/python/cpython/blob/main/Doc/reference/expressions.rst)</sup>。

Lean 证明助手以定理本身来命名这一约定：`Int.ediv` 与 `Int.emod` 实现欧几里得除法，当 \(y \neq 0\) 时满足 \(0 \le \operatorname{emod}\ x\ y < \operatorname{natAbs}\ y\)，这一选择是为了与 SMT-LIB 和 Mathlib 保持一致；在该约定下，商在 \(y > 0\) 时为 \(\lfloor x/y \rfloor\)，在 \(y < 0\) 时为 \(\lceil x/y \rceil\)<sup>[14](https://leanprover-community.github.io/mathlib4_docs/Init/Data/Int/DivMod/Basic.html)</sup>。

## References

1. [4.1. Divisibility and Modular Arithmetic, Discrete Structures for Computing (Western University)](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)
2. [NumberTheory, James Aspnes, Yale University](https://cs.yale.edu/homes/aspnes/pinewiki/NumberTheory.html)
3. [The division algorithm with remainder, UMD 403 Undergraduate Algebra](https://math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)
4. [Abstract Algebra, Chapter 5: Advanced ring theory, Romyar Sharifi (UCLA)](https://math.ucla.edu/~sharifi/notes/algebra-ch05.html)
5. [RES.18-012 Algebra II Student Notes, MIT OpenCourseWare (Spring 2022)](https://ocw.mit.edu/courses/res-18-012-algebra-ii-student-notes-spring-2022/mit18_702s22_full_lec.pdf)
6. [Math 525 chapter summary, Dikran Karagueuzian, Binghamton University](https://people.math.binghamton.edu/dikran/525/summary.html)
7. [The Algorithm as a Concept: From Euclid to Turing, Geschichte der Informatik](https://www.geschichte-der-informatik.de/articles/the_algorithm_as_a_concept/)
8. [Euclid's Number-Theoretical Work, arXiv:0902.2465](https://arxiv.org/abs/0902.2465)
9. [The Division Algorithm / Euclidean Domains, IAAWA (University of Tennessee)](https://web.math.utk.edu/~dcartwr1/iaawa/section-poly-division-algorithm.html/section-euclidean-domains.html)
10. [An Abstract Algebra Primer, Dennis Clark, Carnegie Mellon University](https://andrew.cmu.edu/~dennisc2/alg-primer.pdf)
11. [Other Examples of Principal Ideal Domains that are not Euclidean Domains, N. Allo-Gómez, arXiv:2503.17464](https://arxiv.org/abs/2503.17464)
12. [Arithmetic operators, cppreference.com](https://en.cppreference.com/cpp/language/operator_arithmetic)
13. [Python language reference: expressions, CPython documentation](https://github.com/python/cpython/blob/main/Doc/reference/expressions.rst)
14. [Init.Data.Int.DivMod.Basic, Lean 4 / Mathlib documentation](https://leanprover-community.github.io/mathlib4_docs/Init/Data/Int/DivMod/Basic.html)

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

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Elementary and formal arithmetic › Elementary arithmetic operations

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/euclidean-division

English original: https://www.edgepedia.org/euclidean-division
