# 带余除法

带余除法是初等数论中的一个定理，它断言：对任意整数和任意非零除数，都存在唯一的整数——商与余数——满足一个带余除法等式，且余数被限制在一个固定范围内。尽管名为“算法”，它本质上是一个存在性与唯一性命题；其证明给出了一种计算这两个值的程序，而这一名称也涵盖了由该定理导出的具体算法。<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 陈述（整数情形） | 对整数 \(a > 0\) 与 \(b\)，存在唯一的整数 \(q\) 与 \(r\)，使得 \(b = aq + r\) 且 \(0 \leq r < a\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> |
| 名称 | \(q\) 称为商，\(r\) 称为余数；相应的运算记作 div 与 mod，或 quot(a, b) 与 rem(a, b)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup><sup> • </sup><sup>[2](https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec29-division.html)</sup> |
| 商的公式 | \(q = \lfloor b/a \rfloor\)，且 \(r = b - aq\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> |
| 算例 | \(14 = 3 \cdot 4 + 2\)，即 3 除 14 得 4 余 2；\(-13 = 3 \cdot (-5) + 2\)<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup><sup> • </sup><sup>[3](https://mat112.uncg.edu/HTML/secdivalg.html)</sup> |
| 余数条件的作用 | 若不要求 \(r \geq 0\)，即使在整数中唯一性也不成立：\(3 = 2 \cdot 2 - 1 = 1 \cdot 2 + 1\)<sup>[4](https://math.stackexchange.com/questions/375071/uniqueness-of-q-and-r-of-division-algorithm-doesnt-hold-in-a-general-euclid?noredirect=1)</sup> |
| 推广 | 在带赋值 \(\nu\) 的欧几里得整环中，带余除法给出 \(a = qb + r\)，其中 \(r = 0\) 或 \(\nu(r) < \nu(b)\)；商与余数唯一当且仅当 \(\nu(a+b) \leq \max\{\nu(a), \nu(b)\}\)<sup>[5](https://planetmath.org/uniquenessofdivisionalgorithmineuclideandomain)</sup> |
| 用途 | 它是整除判别法的基础（\(a\) 整除 \(b\) 当且仅当余数为 0），并用于证明算术基本定理<sup>[6](https://www.utica.edu/faculty_staff/jpeter/mat147notesch3.pdf)</sup><sup> • </sup><sup>[7](https://www.math.uh.edu/~minru/web/divis5.html)</sup> |

## 陈述与记号

该定理最常见的形式取除数为正数。设 \(a\) 为整数，\(b\) 为正整数；则存在唯一的整数 \(q\) 与 \(r\)，使得

\[ a = bq + r \quad \text{且} \quad 0 \leq r < b. \]

整数 \(q\) 称为商，\(r\) 称为余数。<sup>[7](https://www.math.uh.edu/~minru/web/divis5.html)</sup> 以任意符号的非零除数列出的版本与此等价：若 \(a < 0\)，关系式 \(b = aq + r\) 可改写为 \(b = a'q' + r\)，其中 \(a' = -a\)、\(q' = -q\)，因此只需对正除数证明该定理即可。<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>

两个输出各有自己的记号。由欧几里得除法引出两个子运算 div 与 mod：\(b \operatorname{div} a = q\)，\(b \bmod a = r\)。<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> 课程讲义常写作 \(\operatorname{quot}(a,b)\) 与 \(\operatorname{rem}(a,b)\)，或定义 \(\operatorname{Mod}(n,d) := r\)。<sup>[2](https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec29-division.html)</sup><sup> • </sup><sup>[8](https://www.math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)</sup> 正是唯一性这一条，使 quot 与 rem 成为从 \(\mathbb{Z} \times \mathbb{Z}\) 到 \(\mathbb{Z}\) 的良定义函数。<sup>[2](https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec29-division.html)</sup>

## 余数条件为何重要

不等式 \(0 \leq r < b\) 并非装饰；正是它从无穷多种分解中挑出了一对 \((q, r)\)。单在整数中，\(3 = 2 \cdot 2 - 1 = 1 \cdot 2 + 1\)，可见若不对余数加以约束，商与余数并不唯一。<sup>[4](https://math.stackexchange.com/questions/375071/uniqueness-of-q-and-r-of-division-algorithm-doesnt-hold-in-a-general-euclid?noredirect=1)</sup>

标准的唯一性论证说明了为何这一范围能锁定答案。设 \(a = q_1 b + r_1 = q_2 b + r_2\)，两个余数都在 \([0, b)\) 内，且 \(r_2 > r_1\)。则 \(b(q_1 - q_2) = r_2 - r_1\)，故 \(b\) 整除 \(r_2 - r_1\)。但 \(0 < r_2 - r_1 < b\)，而 \(b\) 的倍数为 \(0, \pm b, \pm 2b, \ldots\)，所以没有非零的 \(b\) 的倍数严格介于 0 与 \(b\) 之间。因此 \(r_2 = r_1\)，再由 \(b \neq 0\) 推得 \(q_1 = q_2\)。<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup>

## 计算商与余数

存在性证明同时兼作一种程序。某教材的证明对 \(n > 0\) 给出：令 \(r = n\)、\(q = 0\)；若 \(r < d\)，停止；否则将 \(r\) 换成 \(r - d\)、\(q\) 换成 \(q + 1\)，重复进行。该证明被描述为给出了一种计算 \(q\) 与 \(r\) 的算法，尽管效率并不高。<sup>[8](https://www.math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)</sup> 同样的反复相减思想也出现在计算机课程中：从 \(a\) 中尽可能多地减去 \(b\)；相减的次数就是商，剩下的就是余数。<sup>[3](https://mat112.uncg.edu/HTML/secdivalg.html)</sup>

更快的实用途径是使用下取整函数。由于 \(aq \leq b < a(q+1)\) 蕴含 \(q \leq b/a < q + 1\)，故商为 \(q = \lfloor b/a \rfloor\)，余数则为 \(r = b - aq\)。<sup>[1](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)</sup> 对大数进行手算时，步骤是：取 \(a/b\) 的整数部分作为 \(q\)，再计算 \(r = a - bq\)。<sup>[7](https://www.math.uh.edu/~minru/web/divis5.html)</sup>

负被除数需要小心处理。对正 \(a\) 的反复相减算法在 \(a < 0\) 时返回 \((0, a)\)，违反 \(0 \leq r\)，因此需要另设算法处理该情形。<sup>[3](https://mat112.uncg.edu/HTML/secdivalg.html)</sup> 正确处理之后，\(-13\) 除以 \(3\) 得 \(q = -5\)、\(r = 2\)，写作 \(-13 = 3 \cdot (-5) + 2\)；同样，\(-20 \operatorname{div} 7 = -3\)，\(-20 \bmod 7 = 1\)。<sup>[3](https://mat112.uncg.edu/HTML/secdivalg.html)</sup>

## 编程语言中的除法

该定理确定了数学上的定义，但各编程语言在被除数为负时对商的舍入方式并不一致，多种约定并存。微软研究院的一份综述列举了截断除法、Knuth 的下取整除法，以及较少见但更符合数学定义的欧几里得除法，作为计算机科学文献与编程语言中 div 与 mod 的常见定义。<sup>[9](https://www.microsoft.com/en-us/research/publication/division-and-modulus-for-computer-scientists/)</sup>

标准已向下取整约定靠拢。在语言无关算术标准 LIA-1 的 2012 年更新中，截断除法因存在误用风险而被完全删除，下取整除法被赋予符号 \(quot_I(x,y) = \lfloor x/y \rfloor\) 表示商，\(mod_I\) 表示余数。<sup>[10](https://math.stackexchange.com/questions/4661801/name-for-integer-quotient-rounded-up-ceiling-instead-of-down-floor-and-it)</sup> Scheme 直接暴露了这一区别：`truncate/` 将商向零舍入，而 `euclidean-quotient` 实现欧几里得除法的商。<sup>[11](https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/Numerical-operations.html)</sup> 康奈尔大学的课程讲义警告说，相对于欧几里得定义，许多语言在被除数为负时给出的余数是错误的。<sup>[2](https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec29-division.html)</sup>

## 推广到欧几里得整环

整数情形的定理可推广到任意欧几里得整环，即配有赋值 \(\nu\)、支持带余除法的环：对非零元素 \(a, b\)，存在 \(q, r\) 使得 \(a = qb + r\)，其中 \(r = 0\) 或 \(\nu(r) < \nu(b)\)。<sup>[5](https://planetmath.org/uniquenessofdivisionalgorithmineuclideandomain)</sup> 与采用标准赋值的整数情形不同，这里的商与余数未必唯一。PlanetMath 记录了确切的判据：它们唯一当且仅当对所有非零 \(a, b\) 有 \(\nu(a+b) \leq \max\{\nu(a), \nu(b)\}\)。当该条件不成立时，两种分解可以并存，例如只要 \(\nu(b) < \nu(a+b)\) 且 \(\nu(a) < \nu(a+b)\)，就有 \(b = 0 \cdot (a+b) + b = 1 \cdot (a+b) - a\)。<sup>[5](https://planetmath.org/uniquenessofdivisionalgorithmineuclideandomain)</sup>

20 世纪 60 年代的一个定理完整刻画了那些除法过程总能给出唯一商与余数的欧几里得整环；由于该定理采用的是欧几里得整环较旧、较窄的定义，在现代定义下该结果是否仍然成立一直悬而未决。<sup>[12](https://arxiv.org/abs/2604.24399)</sup> Senan Sekhon 在 2026 年的一篇论文中证明了答案是肯定的。<sup>[12](https://arxiv.org/abs/2604.24399)</sup>

## 在数论中的地位

带余除法是初等数论的起点：几乎所有的初等数论教材都以它开篇。<sup>[13](https://arxiv.org/abs/0902.2465)</sup> 它给出了整除判别法，即 \(a\) 整除 \(b\) 当且仅当定理所保证的余数为 0，<sup>[6](https://www.utica.edu/faculty_staff/jpeter/mat147notesch3.pdf)</sup> 并用于证明算术基本定理。<sup>[7](https://www.math.uh.edu/~minru/web/divis5.html)</sup> 它的历史根源是欧几里得算法：可以证明欧几里得算法本质上等价于贝祖等式与带余除法，而欧几里得关于整除与最大公因数的初步理论正是以此为数论奠定了基础。<sup>[13](https://arxiv.org/abs/0902.2465)</sup>

## References

1. [Division with remainder (Euclidean division), Discrete Structures for Computing, Western University](https://www.csd.uwo.ca/~abrandt5/teaching/DiscreteStructures/Chapter4/div-mod.html)
2. [Euclidean division, CS 2800 lecture notes, Cornell University](https://www.cs.cornell.edu/courses/cs2800/2017sp/lectures/lec29-division.html)
3. [Section 3.2 Division Algorithm, MAT 112, University of North Carolina at Greensboro](https://mat112.uncg.edu/HTML/secdivalg.html)
4. [Uniqueness of q and r of Division Algorithm in a general Euclidean Domain, Mathematics Stack Exchange](https://math.stackexchange.com/questions/375071/uniqueness-of-q-and-r-of-division-algorithm-doesnt-hold-in-a-general-euclid?noredirect=1)
5. [Uniqueness of division algorithm in Euclidean domain, PlanetMath](https://planetmath.org/uniquenessofdivisionalgorithmineuclideandomain)
6. [The Division Algorithm and the Euclidean Algorithm, course notes, Utica College](https://www.utica.edu/faculty_staff/jpeter/mat147notesch3.pdf)
7. [Section 1.5: The Division Algorithm, University of Houston](https://www.math.uh.edu/~minru/web/divis5.html)
8. [The division algorithm with remainder, UMD 403 Undergraduate Algebra, University of Maryland](https://www.math.umd.edu/~pbrosnan/notes/ugalg/sect0005.html)
9. [Division and Modulus for Computer Scientists, Microsoft Research](https://www.microsoft.com/en-us/research/publication/division-and-modulus-for-computer-scientists/)
10. [Name for integer quotient rounded up (ceiling) instead of down (floor), Mathematics Stack Exchange](https://math.stackexchange.com/questions/4661801/name-for-integer-quotient-rounded-up-ceiling-instead-of-down-floor-and-it)
11. [Numerical operations, MIT/GNU Scheme 12.1 reference](https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/Numerical-operations.html)
12. [Senan Sekhon, A Necessary and Sufficient Condition for Uniqueness of Euclidean Division, arXiv](https://arxiv.org/abs/2604.24399)
13. [Euclid's Number-Theoretical Work, arXiv](https://arxiv.org/abs/0902.2465)

---
*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: 物质世界与数学 › 数学与统计学 › 数与代数 › Number theory › Elementary number theory › Divisibility, GCD, and the integers

Copyright 2026 Edgepedia

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

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

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