a mod b
Compute the remainder and quotient of an integer division.
📐 计算公式
a mod b = a − b × ⌊a ÷ b⌋(向下取整商 q、配套余数 r)。r 与除数 b 同号:b>0 时 0≤r<b,b<0 时 b<r≤0;如 −7 mod 3 = 2、7 mod −3 = −2。校验:a、b 必填且有限,b=0 无定义;辅助比值 b/a 在 a=0 时无定义。主结果、表格、参考值与导出统一用 q、r。
求 a 除以 b 的余数。
📚 常见模数下的余数(a mod m)
🔢 同余性质(gcd 与模逆元)
📈 余数随模数变化(a mod m, m=2..16)
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Modulo operation | a mod b = a - b · floor(a/b) | Knuth DE, The Art of Computer Programming, Vol. 1, §1.2.4 |
| Division with remainder | a = b · q + r with 0 <= r < |b| | Knuth DE, The Art of Computer Programming, Vol. 1, §1.2.4 |
| Congruence | a ≡ b (mod m) means m divides a - b | Gauss CF, Disquisitiones Arithmeticae (1801) |
| Negative operand caveat | Languages differ on the sign of the result for negative operands | ISO/IEC 10967-1:2012, Language independent arithmetic |
📌 计算说明
- 17 mod 5 = 2。
- 用于周期与同余。