2.5.6 · D3Number Theory (Intermediate)

Worked examples — Modular arithmetic — definition, addition, multiplication, congruence

2,010 words9 min readBack to topic

This page is a drill floor. The parent note taught you the rules; here we throw every kind of input at those rules — positive, negative, zero, huge powers, word problems, and one exam trap — so that no future problem surprises you.

Before any symbol appears, one reminder in plain words: writing means " and land on the same spot on a circle with marks numbered ." The mark you land on is the remainder after dividing by . That circle is the picture behind every example below.

Figure — Modular arithmetic — definition, addition, multiplication, congruence

Look at the red mark: it is position on a circle of marks. Every number that leaves remainder when divided by — that is and also — sits on that same red mark. That is the whole idea of a "bucket."


The scenario matrix

Every problem this topic can throw is one of these cells. Each worked example below is tagged with the cell it covers.

Cell Scenario Danger it tests
A Positive positive reduce-first habit
B Positive positive reduce both factors
C Negative input wrapping into
D Subtraction (a special negative) can go below zero
E Large power, base trivial-base shortcut
F Large power, base finding the cycle length
G Zero / degenerate (, or ) edge behaviour
H Word problem (real-world clock/calendar) translating to
I Exam twist — illegal "division" the coprime condition

Nine cells. Nine (and one bonus) worked examples follow. Prerequisites you may want open: Division Algorithm, GCD and LCM, Modular Inverses.


Example 1 — Cell A (positive + positive)

Forecast: Guess the final answer (a number between and ) before reading on.

  1. Reduce each operand. , so . And , so . Why this step? The addition rule says congruent numbers may be swapped for their remainders before adding — smaller numbers are safer to handle.
  2. Add the small numbers. . Why this step? By the addition rule .
  3. Is it in range? , so we stop. Why this step? Standard form lives in .

Answer: .

Verify: . Remainder . ✓


Example 2 — Cell B (positive × positive)

Forecast: Multiplying gives — but you should be able to name the remainder without that.

  1. Reduce each factor. . . Why this step? The multiplication rule lets us replace each factor by its remainder.
  2. Multiply the reduced values. . Why this step? .
  3. Reduce the product. , already standard.

Answer: .

Verify: . Remainder . ✓


Example 3 — Cell C (negative input)

Forecast: A negative number must still land on a mark in . Which one?

Figure — Modular arithmetic — definition, addition, multiplication, congruence
  1. Divide, allowing a negative quotient. We need with . Try : , and . Why this step? The Division Algorithm guarantees a unique remainder in even for negatives — we just pick small enough.
  2. Read off the remainder. , so . Why this step? That is the mark we land on when stepping backwards around the circle (red arrow in the figure).
  3. Shortcut check. Equivalently, add multiples of until non-negative: . Same answer.

Answer: .

Verify: , a multiple of . ✓


Example 4 — Cell D (subtraction dipping below zero)

Forecast: Subtraction is just "add a negative," so expect a wrap-around.

  1. Reduce each term. (already small); . Why this step? Reduce before operating, exactly as with addition — subtraction obeys the same swap rule.
  2. Subtract the reduced values. . Why this step? .
  3. Fix the sign if needed. Here , so no wrap is required.

Answer: .

Verify: , and . So . ✓


Example 5 — Cell E (large power, base ≡ 1)

Forecast: An exponent of looks terrifying. It won't be.

  1. Reduce the base. . Why this step? If the base is , the power rule collapses everything.
  2. Apply the power rule. . Why this step? Congruence survives exponentiation: .
  3. Evaluate. .

Answer: .

Verify: Since , every power of is . Check tiny case . ✓ (Compare with Fermats Little Theorem for a deeper reason powers cycle.)


Example 6 — Cell F (large power, base ≢ ±1 — find the cycle)

Forecast: Here , so we cannot collapse the base. Guess whether the answer is small.

Figure — Modular arithmetic — definition, addition, multiplication, congruence
  1. List the powers of until they repeat. , , , , , . Why this step? Powers must cycle (only possible remainders), and the moment we hit the pattern restarts. The cycle length here is .
  2. Use the cycle to shrink the exponent. Since , reduce modulo the cycle length : , so the leftover exponent is . Why this step? .
  3. Read the answer off the list. From step 1, .

Answer: .

Verify: The cycle (red loop in the figure) repeats every ; position gives the th entry . ✓


Example 7 — Cell G (zero / degenerate)

Forecast: Edge cases. Do the rules still hold when a factor is , or the modulus is ?

  1. Part (a): a zero factor. , so . Why this step? The multiplication rule works for any residues, including . Zero times anything is , and is already standard.
  2. Part (b): modulus . With , the marks on the circle are just — a single point. Every integer leaves remainder . Why this step? , so . In mod arithmetic all numbers collapse to one class.

Answers: (a) . (b) .

Verify: (a) . ✓ (b) , a multiple of . ✓


Example 8 — Cell H (real-world word problem)

Forecast: Weeks are a circle of marks. Guess a day.

Figure — Modular arithmetic — definition, addition, multiplication, congruence
  1. Model days as marks mod 7. Number the days Wed, Thu, Fri, Sat, Sun, Mon, Tue. Why this step? A week is a -mark clock; "in days" means stepping marks forward.
  2. Reduce the step count. , so . Why this step? Whole weeks ( of them) return you to the same day, so only the leftover steps matter.
  3. Step forward from Wed. Tuesday.

Answer: In days it will be Tuesday.

Verify: and , . ✓ Six days after Wednesday: Thu, Fri, Sat, Sun, Mon, Tue. ✓


Example 9 — Cell I (exam twist: illegal division)

Forecast: Your instinct says "divide both sides by ." Resist — check the gcd first.

  1. Check whether you may divide by . , so has no modular inverse mod ; naive division is forbidden. Why this step? Cancelling by is only legal when (see GCD and LCM).
  2. Divide the whole congruence by the common factor . Since divides , , and : . Why this step? When divides , you may divide , , and all by . This is the legal move — a Linear Congruences technique.
  3. Now , so invert mod . We need ; testing, , so . Why this step? With a genuine inverse we may finally "divide."
  4. Multiply through by . .

Answer: — equivalently as residues mod .

Verify: Take : . ✓ Take : . ✓ Take : . ✓


Recall Self-test (reveal after answering)

How do you reduce a negative number to standard form? ::: Add the modulus repeatedly until the result lands in . Why can be found instantly? ::: Because , and to any power is . For , what number do you reduce the exponent by? ::: The cycle length (since ), giving leftover exponent . When is dividing both sides of a congruence by legal? ::: Only when .