📘 CodingMarble Learn

Modular Arithmetic: Remainders and Congruences

Euclidean division writes any integer a as a = n × q + r with 0 ≤ r < n. The remainder r is "a mod n". Two numbers are congruent modulo n (a ≡ b mod n) when they leave the same remainder, which means n divides a − b. Congruences can be added, subtracted, multiplied and raised to powers, so we can find remainders of huge numbers using small ones. Remainders of powers repeat in cycles.

🎬 Step-by-step story

  1. 17 blocks in rows of 5: 3 full rows and 2 left. So 17 = 5 × 3 + 2. The remainder 2 is smaller than 5.
  2. A 5-hour clock. A marble walks 17 steps from 0, goes round 3 times and stops at 2. So 17 ≡ 2 (mod 5).
  3. 2, 7, 12 and 17 all stop at 2. Their differences are multiples of 5. They are congruent mod 5.
  4. To add, add the remainders: 17 → 2, 9 → 4, and 2 + 4 = 6 → 1. So 26 ≡ 1 (mod 5).
  5. Powers of 2 mod 5 go 2, 4, 3, 1 and then repeat. Every 4th power lands on 1.
  6. Free play: choose the clock size and a number. Watch a = m × q + r appear.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why must the remainder be smaller than the divisor?

If 5 or more were left over, you could make one more full row of 5. So the leftover is always 0 to 4.

What does ≡ mean, and how is it different from =?

≡ (mod 5) means "stops at the same place on the 5-clock". 17 and 2 are not equal, but they land together.

How do I check if two numbers are congruent quickly?

Subtract them. If the difference is a multiple of n, they are congruent mod n.

Why can I replace big numbers by their remainders before adding?

Full laps do not change where you stop. 17 is 3 laps + 2 steps; the laps add nothing on the clock.

How do I find the remainder of a huge power?

List the first few powers mod n until you see 1 or a repeat. Then use the exponent’s remainder in that cycle.

What happens for negative numbers?

Walk backwards on the clock. −3 on a 5-clock stops at 2, so −3 ≡ 2 (mod 5).

Divisibility and Euclidean division

We say n divides a (written n | a) if a = n × k for some integer k. Example: 5 | 35 because 35 = 5 × 7.

Euclidean division: for any integer a and any whole number n ≥ 1, there is exactly one pair q, r with

a = n × q + r, and 0 ≤ r < n.

q is the quotient, r the remainder. For negative a, the remainder is still between 0 and n − 1: −7 = 5 × (−2) + 3, so the remainder is 3, not −2.

Useful facts: if n | a and n | b, then n divides a + b, a − b and any a × x + b × y.

Congruence modulo n

a ≡ b (mod n) means a and b leave the same remainder when divided by n. Equivalently, n | (a − b).

Think of a clock with n numbers: congruent numbers stop at the same place.

Operations with congruences

If a ≡ b and c ≡ d (mod n), then:

Remainders of powers repeat in a cycle. Find the cycle, then use the exponent’s remainder.

Example: 3k mod 7 gives 3, 2, 6, 4, 5, 1, then repeats every 6. So 3100: 100 = 6 × 16 + 4, so 3100 ≡ 34 ≡ 4 (mod 7).

Careful: you cannot always divide. 2 × 3 ≡ 2 × 8 (mod 10) but 3 ≢ 8 (mod 10). You may cancel a factor only if it shares no common factor with n.

Divisibility rules explained by congruences

Example: 7 392: digit sum 21 is divisible by 3, so 7 392 is too. Alternating sum 2 − 9 + 3 − 7 = −11, so it is divisible by 11.

Solving simple integer equations

Congruences show quickly when an equation has no integer solution. Example: x² = 4y + 3. Squares mod 4 are only 0 or 1 (0² = 0, 1² = 1, 2² = 4 ≡ 0, 3² = 9 ≡ 1), but the right side is ≡ 3 (mod 4). So no integers work.

Linear congruence 3x ≡ 4 (mod 7): try x = 0…6: 3 × 6 = 18 ≡ 4, so x ≡ 6 (mod 7), i.e. x = 7k + 6.

Key formulas and definitions

Worked examples

1. Write the Euclidean division of 100 by 7.

7 × 14 = 98 and 100 − 98 = 2. So 100 = 7 × 14 + 2: q = 14, r = 2.

2. Find the remainder when −23 is divided by 6.

6 × (−4) = −24, and −23 − (−24) = 1. So −23 = 6 × (−4) + 1, remainder 1 (between 0 and 5).

3. Is 1 234 ≡ 4 (mod 9)?

Digit sum = 1 + 2 + 3 + 4 = 10 ≡ 1 (mod 9). So 1 234 ≡ 1, not 4. The statement is false.

4. Find the remainder of 47 × 58 when divided by 5.

47 ≡ 2 and 58 ≡ 3 (mod 5). 2 × 3 = 6 ≡ 1. Remainder 1. (Check: 47 × 58 = 2 726 = 5 × 545 + 1.)

5. Find the remainder when 2¹⁰⁰ is divided by 7.

2¹ ≡ 2, 2² ≡ 4, 2³ = 8 ≡ 1 (mod 7). Cycle length 3. 100 = 3 × 33 + 1, so 2¹⁰⁰ = (2³)³³ × 2 ≡ 1 × 2 = 2.

6. Show that n³ − n is divisible by 3 for every integer n.

n ≡ 0, 1 or 2 (mod 3). n³ − n = (n − 1)n(n + 1). Check: 0 → 0; 1 → 0; 2 → 8 − 2 = 6 ≡ 0. In every case it is ≡ 0, so 3 divides it.

Common mistakes

Practice quiz

1. What is the remainder when 29 is divided by 4?
2. a ≡ b (mod n) means:
3. 38 ≡ ? (mod 6)
4. A number is divisible by 9 when:
5. Remainder of 3⁴ when divided by 5:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is modular arithmetic in simple words?

It is arithmetic with remainders, like a clock: after reaching n you start again at 0.

How do you calculate a mod n?

Divide a by n and keep the remainder r with 0 ≤ r < n. Example: 23 mod 7 = 2 because 23 = 7 × 3 + 2.

Where is modular arithmetic used?

Clocks and calendars, check digits (ISBN, barcodes, card numbers), hashing in computers and cryptography such as RSA.

Where this is taught

CBSE (India)Class 12Numbers, Quantification and Numerical Applications
FranceTerminaleArithmetic
Russia8 классNumbers and calculations

Learn first

Learn next

Related lessons

All Maths lessons