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。
  • 用於週期與同餘。