Modulus Remainder Calculator

Compute remainders with Euclidean or truncated definitions precisely everywhere. Support negatives, big integers, and stepwise explanations for clarity. Batch evaluate many pairs and compare scenarios instantly too. Export tables to CSV or PDF effortlessly anytime. Clean interface, white theme, accurate math, fast results always.

Single Calculation

Batch Mode

Enter one pair per line as a,n,mode. Mode is euclidean or truncated. Mode optional; defaults to current selector.

# a n Mode q r Identity

Example Data Table

anModeqrIdentity
-175Euclidean-43-17 = (-4)·5 + 3
-175Truncated-3-2-17 = (-3)·5 + (-2)
1234567890123456789097Euclidean1272709175350099681412345678901234567890 = 127270917535009968·97 + 14
4210Euclidean4242 = 4·10 + 2

Formula Used

Euclidean remainder: For integer a and modulus n > 0, the remainder r is defined by r = a − n ⌊a / n⌋ with 0 ≤ r < n. The quotient is q = ⌊a / n⌋.

Truncated remainder: Some languages define q as the integer part truncated toward zero, i.e. q = trunc(a / n), then r = a − n·q, which may be negative when a is negative.

When numbers exceed native integer size, this tool computes Euclidean remainder using a string-based reduction algorithm requiring n to fit within native integer range.

How to Use This Calculator

  1. Enter the dividend a and a positive modulus n.
  2. Choose the remainder convention: Euclidean for non‑negative remainders, or Truncated to match many programming environments.
  3. Click Calculate to see q, r, and the identity a = q·n + r.
  4. Use Batch Mode to process many lines at once.
  5. Download your results table as CSV or PDF for reports.
  6. Refer to the Formula Used and FAQs if unsure about conventions.

FAQs

Euclidean remainders are always between 0 and n−1. Truncated remainders follow the sign of the dividend, which can produce negative remainders for negative dividends.

No. This tool assumes n > 0. A non‑positive modulus is undefined for the conventions provided here.

If inputs exceed native integer size, a string‑based algorithm computes the Euclidean remainder provided n fits in the native integer range. Truncated remainder for huge integers is not computed.

Choose Euclidean for number theory and cryptography. Choose truncated when matching environments where integer division truncates toward zero and the remainder follows the dividend sign.

Different tools use different conventions. Ensure you compare results using the same remainder definition and sign convention.

Yes. Use the CSV or PDF buttons to export your batch results and share them with collaborators or include them in reports.

Language Conventions & Examples

When n > 0, different environments use different remainder conventions. Examples shown for a = -17, n = 5.

Environment Division Rule Remainder Sign Example Result Notes
Python (%) Floor division pairing Non-negative when n > 0 -17 % 5 = 3 a == (a//n)*n + (a%n)
C / C++ (%) Truncate toward zero Same sign as dividend -17 % 5 = -2 q = trunc(a/n)
Java (%) Truncate toward zero Same sign as dividend -17 % 5 = -2 Matches C family behavior
JavaScript (%) Truncate toward zero Same sign as dividend -17 % 5 = -2 Remainder, not true modulo
MATLAB mod(a,n) Euclidean-style Non-negative when n > 0 mod(-17,5) = 3 rem(a,n) would give -2
R (%%) Euclidean-style for n > 0 Non-negative when n > 0 -17 %% 5 = 3 Pairs with integer division %/%
Ruby (%) Floor division pairing Sign of divisor -17 % 5 = 3 Non-negative when n > 0

Residue Class Patterns

Euclidean remainder classes group integers that share the same remainder. Below are compact examples for common moduli.

Modulo 5 (Euclidean)

rExample a values
0-20, -15, -10, -5, 0, 5, 10, 15, 20
1-19, -14, -9, -4, 1, 6, 11, 16, 21
2-18, -13, -8, -3, 2, 7, 12, 17, 22
3-17, -12, -7, -2, 3, 8, 13, 18, 23
4-16, -11, -6, -1, 4, 9, 14, 19, 24
Pattern repeats every 5 integers; add or subtract multiples of 5.

Modulo 7 (Euclidean)

rExample a values
0-14, -7, 0, 7, 14, 21
1-13, -6, 1, 8, 15, 22
2-12, -5, 2, 9, 16, 23
3-11, -4, 3, 10, 17, 24
4-10, -3, 4, 11, 18, 25
5-9, -2, 5, 12, 19, 26
6-8, -1, 6, 13, 20, 27
Pattern repeats every 7 integers; add or subtract multiples of 7.

Related Calculators

Proportion and Ratio Calculatorsquare root calculator with stepsnegative square root calculatorfraction square root calculatorsquare root division calculatordecimal to square root calculatorderivative of square root calculatorharmonic mean calculatorbinomial distribution mean calculatordiscrete random variable mean calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.