NapkinCalc

Discrete Mathematics — Logic & Number Theory

Modular arithmetic & GCD

continues from lesson 2 — values defined earlier in the course stay live here

ELI5: modular arithmetic is clock math — after 12 it wraps to 1. "17 mod 5" is the remainder, 2. The greatest common divisor gcd(a, b) is the largest number dividing both. Both are engine built-ins.

clock=mod(15+20,24)clock = \mathrm{mod}\left(15 + 20, 24\right) = 1111 15:00 plus 20 hours, on a 24-hour clock: 11:00
share=gcd(48,36)share = \mathrm{gcd}\left(48, 36\right) = 1212 largest tile that paves a 48×36 floor: 12
✓ pass clock==11andshare==12clock == 11 and share == 12 the wrap-around and the common divisor

Real-world hook: modular arithmetic powers cryptography (RSA, hashing), check digits on credit cards & ISBNs, and anything cyclic — days of the week, clock faces, circular buffers.

Try it yourself: on a 24-hour clock, what time is it 20 hours after 15:00? (Use mod(15 + 20, 24).)

timeyou=mod(15+20,24)time_{you} = \mathrm{mod}\left(15 + 20, 24\right) = 1111 ✏️ Your turn: wrap 15 + 20 around a 24-hour clock with mod(…, 24).
✓ pass timeyou==mod(15+20,24)time_{you} == mod(15 + 20, 24) green when your clock math wraps correctly