The modulo operation gives the remainder of a division. The modulo calculator computes a mod n with the mathematical convention, the truncated remainder that programming languages use, the floor quotient and the sum and product modulo n, for positive and negative integers.
How the calculation works
- Enter the integer a that you divide and the modulus n, which must be a positive integer.
- Optionally enter a second integer b to compute the sum and the product modulo n.
- The calculator gives a mod n with the mathematical convention, which is always between 0 and n − 1, even when a is negative.
- It also shows the truncated remainder used by many programming languages, the floor quotient and the results of (a + b) mod n and (a × b) mod n.
Example
For a = 1,234 and n = 7, the floor quotient is 176 and 1,234 mod 7 = 2, because 1,234 = 7 × 176 + 2. With b = 89, which is 5 mod 7, (a + b) mod 7 is 1,323 mod 7 = 0 and (a × b) mod 7 is 109,826 mod 7 = 3. The same results come from using the residues, 2 + 5 = 7 ≡ 0 and 2 × 5 = 10 ≡ 3.
Why it matters
The calculator helps students of arithmetic and computer science, programmers who need to know how their language handles negative numbers, and puzzle lovers who work with clocks, calendars and cycles. It makes the difference between the mathematical and the truncated remainder clear.
Good to know
The calculator works with integers up to ten million in absolute value, so that the products stay exact. The modulus must be positive. Powers and modular inverses, which need many steps, are not included. Some languages define the modulo of negative numbers differently, so check your own language.
Related tools
The GCD and LCM calculator finds common divisors and multiples, the remainder calculator divides numbers with a remainder, the factorial calculator multiplies consecutive integers, and the fraction calculator works with ratios of integers.