Qm
Core

Modular Arithmetic in Puzzles

A toolkit of remainder-based shortcuts, working with what's left over after division, that turns brainteaser questions about cycles, patterns, and divisibility into a couple of lines of arithmetic.

Modular arithmetic asks only about the remainder left after dividing by some fixed number, called the modulus, and interview puzzles frequently collapse into a one-line remainder calculation once you spot the cycle. Writing "ab(modn)a \equiv b \pmod{n}" just means aa and bb leave the same remainder when divided by nn, for instance 172(mod5)17 \equiv 2 \pmod{5}, since both leave remainder 2.

A common puzzle type: "if today is Wednesday, what day of the week is it in 100 days?" Since the week cycles every 7 days, only the remainder of 100 divided by 7 matters: 100=14×7+2100 = 14 \times 7 + 2, so the remainder is 2, meaning 2 days after Wednesday, Friday. The trick generalizes to any cyclic pattern: clock hours (mod 12), a repeating digit pattern in a large power (e.g., the last digit of 71007^{100} cycles through 7, 9, 3, 1 every 4 powers, so check 100mod4=0100 \bmod 4 = 0, landing on the 4th element of the cycle, which is 1), or a sequence of coin flips that repeats every kk steps.

The general move in any such puzzle is the same three steps: identify the cycle length, reduce the target number modulo that length, and read off the corresponding position in one cycle, turning what looks like a huge computation into simple division with a remainder.

Whenever a puzzle involves something that repeats in a fixed cycle, the answer only depends on the target number's remainder modulo the cycle length, reduce first, then read off the position in a single cycle.

Discussion

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. Ask and answer about this concept. Off-topic gets removed.
  2. No homework dumps. Show what you tried first.
  3. Corrections are welcome. Cite a source when you claim an error.

Loading discussion…

Related concepts

Practice in interviews

Further reading

  • Engel, Problem-Solving Strategies, ch. on number theory
ShareTwitterLinkedIn