Modular Arithmetic
Learn clock arithmetic: remainders, a mod n, congruence modulo n, and how to use them for calendars, check digits and the last digit of huge powers.
Definition
Try it now
Worked Examples
Find the largest multiple of 6 that is not more than 47
Write 47 as quotient times 6 plus remainder
Check that the remainder is between 0 and 5
Answer: , so . The quotient is not part of the answer.
Common Mistakes
Writing (or )
Why it's wrong: A remainder must be one of . Going 3 hours back from 12 o'clock does not land on a negative number, and not on 3 either.
Correct: Add the modulus until the number is in range: , so .
Saying that 9 o'clock plus 4 hours is 13 o'clock on a 12-hour clock
Why it's wrong: The sum is right, but the last reduction is missing. Every result has to be reduced again.
Correct: : the clock shows 1.
Giving the quotient instead of the remainder:
Why it's wrong: remainder . The mod operation keeps only what is left over, not how many times 6 fits into 47.
Correct: , because .
Reducing the exponent by the modulus: becomes because
Why it's wrong: You may reduce the base modulo , but not the exponent. The exponent follows the length of the power cycle, which here is 3, not 7.
Correct: Powers of 2 modulo 7 are (cycle length 3). , so . Check: .
Interactive Visual
9 o'clock plus 100 hours: watch the laps
12 spots on the dial: mod 12
Start at 9 and move 100 hours forward.
Days of the week are modulo 7: guess first, then watch
7 spots on the dial: mod 7
Where will the hand land? Tap the spot on the dial.
2 + 100 ≡ ? (mod 7)
Start at Wed and move 100 days forward.
Congruent modulo 12: same spot on the dial
12 spots on the dial: mod 12
38 = 3 × 12 + 2
14 = 1 × 12 + 2
38 − 14 = 24 = 2 × 12
38 ≡ 14 (mod 12)
38 and 14 land on the same spot because their difference 24 is a multiple of 12.
Numbers on the spot 2: … -10, 2, 14, 26, 38 …
Last digits of powers of 3 (modulo 10) repeat
10 spots on the dial: mod 10
Multiply by 3 again and again, and keep only the remainder each time.
Interactive Sandbox
Expression Calculator
Try these:
History
No calculations yet
Practice Problems
18 problemsWhy It Matters
- Time: clocks count modulo 12 or 24, weekdays modulo 7. What time is it 100 hours from now? Which day is it in 100 days?
- Check digits: the last digit of a barcode (EAN-13) is chosen modulo 10, an ISBN-10 modulo 11, and the IBAN of a bank account is checked modulo 97. One mistyped digit and the check fails.
- Huge numbers: you can find the last digit of (a number with 48 digits) in your head, because last digits are remainders modulo 10 and they repeat in a cycle.
- Computer science: hash tables, random number generators and the RSA encryption behind online banking all calculate modulo .
Real World Applications
Calendars: Which Day Will It Be?
A week has 7 days, so the days of the week repeat modulo 7. Calendar apps, timetables and birthday puzzles use this all the time.
Example:
A normal year has days and . So a birthday on a Monday this year falls on a Tuesday next year (unless 29 February comes in between).
Today is Wednesday. Your exchange trip starts in exactly 100 days. Number the days Monday , Tuesday , and so on up to Sunday .
On which day of the week does the trip start?
Step 1: Choose the right answer
Pick the day:
Barcodes and Check Digits
The last digit of every EAN-13 barcode is a check digit, chosen with arithmetic modulo 10. The scanner computes it again and rejects a code with a misread digit.
Example:
For the book code the weighted sum (weights ) is , and . The check digit is , so the full code is .
A shop creates a product code with the 12 digits . The digits in positions 1, 3, 5, ... count once, the digits in positions 2, 4, 6, ... count three times. The check digit makes the total a multiple of 10.
What is the check digit?
Step 1: Write the mathematical expression
Check digit:
Shift Work and the 24-Hour Clock
Train timetables, hospital shifts and flight plans use the 24-hour clock, which is arithmetic modulo 24.
Example:
A night shift starts at 22:00 and lasts 9 hours: and , so it ends at 07:00.
A machine test in a factory starts at 19:00 and runs for 75 hours without a break.
At what hour (0 to 23) does the test end?
Step 1: Write the mathematical expression
End hour:
Key Takeaways
- 1 is the remainder of and is always one of
- 2 means that and leave the same remainder, which is the same as dividing
- 3A clock is arithmetic modulo 12, the 24-hour clock modulo 24, the days of the week modulo 7 and even/odd modulo 2
- 4In sums, differences and products you may reduce every number first, then reduce the result once more
- 5For a negative number add until it lands in :
- 6Powers repeat in cycles modulo : find the cycle length and reduce the exponent modulo that length, not modulo
Frequently Asked Questions
Glossary
- Modulus
- The fixed number you divide by; the remainders are (12 on a clock, 7 for weekdays)
- Remainder
- What is left over after dividing: in with it is
- a mod n
- The remainder of divided by , for example and
- Congruent modulo n
- Two numbers with the same remainder modulo , written ; equivalently divides
- Cycle length
- How many steps it takes until the remainders of powers start to repeat, for example 4 for the last digits of powers of 3
- Check digit
- An extra digit at the end of a code (barcode, ISBN) chosen so that a weighted sum is divisible by 10 or 11
Formula Card
Division with remainder
$r$ is $a \bmod n$, $q$ is the quotient
Congruence
Same remainder, or: the difference is a multiple of $n$
Reduce first
The same works for subtraction and multiplication
Negative numbers
Add a multiple of $n$ until the number lands in $0, \ldots, n - 1$: $-3 + 12 = 9$