Inputs
Results Table
| # | a | m | Convention | q | r | Congruence |
|---|
Formula Used
All conventions satisfy the integer division identity a = q·m + r. The conventions differ in how q is chosen, which controls the sign/range of r.
- Euclidean: uses modulus
|m|, choosesq = ⌊a/|m|⌋, giving0 ≤ r < |m|. Implementation trick:r = ((a % |m|) + |m|) % |m|. - Truncated toward zero: chooses
q = trunc(a/m)(e.g.,intdiv), sormay be negative whenais negative. - Floor division remainder: chooses
q = ⌊a/m⌋, sorcan be non‑negative or have the sign ofmdepending on inputs.
For modular arithmetic in number theory, the Euclidean convention is standard: report r ∈ {0,1,…,|m|−1} and write a ≡ r (mod |m|).
How to Use This Calculator
- Enter an integer dividend a and a non‑zero modulus m.
- Select a convention: Euclidean (recommended), Truncated, or Floor.
- Click Calculate to see q, r, steps, and congruence.
- Use Add to table to accumulate multiple calculations.
- Export the table as CSV or as a PDF document.
Tip: For negative moduli, Euclidean mode automatically uses |m| and reports a non‑negative residue.
Example Data Table
Click any row to load its a, m, and convention into the form.
| a | m | Convention | q | r | Congruence |
|---|---|---|---|---|---|
| -13 | 5 | Euclidean | -3 | 2 | -13 ≡ 2 (mod 5) |
| -13 | 5 | Truncated | -2 | -3 | -13 ≡ -3 (mod 5) |
| -13 | 5 | Floor | -3 | 2 | -13 ≡ 2 (mod 5) |
| -7 | 3 | Euclidean | -3 | 2 | -7 ≡ 2 (mod 3) |
| -7 | 3 | Truncated | -2 | -1 | -7 ≡ -1 (mod 3) |
| -7 | -3 | Euclidean | -3 | 2 | -7 ≡ 2 (mod 3) |
| 13 | -5 | Truncated | -2 | 3 | 13 ≡ 3 (mod -5) |
| 13 | 5 | Euclidean | 2 | 3 | 13 ≡ 3 (mod 5) |
Why Different Modulo Conventions Exist
All conventions satisfy a = q·m + r, but each chooses q differently, changing the reported r. This matters when a or m is negative.
- Number Theory: prefers non‑negative residues to represent congruence classes cleanly.
- Systems Programming: truncated division matches legacy machine instructions and is fast.
- Mathematical Analysis: floor division aligns with inequalities and interval reasoning.
When doing modular arithmetic proofs or cryptography, use the Euclidean convention so residues lie in [0, |m| − 1].
Mapping Between Conventions
Given any remainder r_x from a chosen convention and non‑zero m, the Euclidean residue is:
r_e = ((r_x % |m|) + |m|) % |m|
Direct formulas for each convention:
- Truncated:
q_t = trunc(a/m),r_t = a − q_t·m. - Floor:
q_f = ⌊a/m⌋,r_f = a − q_f·m. - Euclidean:
q_e = ⌊a/|m|⌋,r_e = a − q_e·|m|, with0 ≤ r_e < |m|.
Example mapping with a = −13, m = 5:
| Convention | q | r | Note |
|---|---|---|---|
| Truncated | q_t = −2 | r_t = −3 | May return negative remainder. |
| Floor | q_f = −3 | r_f = 2 | Remainder non‑negative for m > 0. |
| Euclidean | q_e = −3 | r_e = 2 | Residue in [0,4]. |
From r_t = −3, compute r_e = ((−3 % 5)+5)%5 = 2.
Common Pitfalls and Quick Checks
- Never use
m = 0; the modulus must be non‑zero. - For Euclidean residues, always verify
0 ≤ r < |m|. - Confirm the identity
a = q·m + rnumerically after each computation. - Mixing conventions can confuse tests; normalize to Euclidean for comparisons.
- Negative m? Use |m| when reporting residues in Euclidean mode.
If portability matters, store normalized Euclidean residues and the original m alongside results.