Practice Discrete Math

Algorithms / Modular Arithmetic

Least You Need to Know: Modular Arithmetic, Divisibility, and Hashing Intuition

Modular arithmetic tracks remainders. That matters in parity, clock arithmetic, hashing buckets, wrap-around indexing, and many programming tasks involving periodic behavior.

The least you need to know

Key notation

a mod m remainder of a on division by m
a ≡ b (mod m) same remainder mod m
key mod m bucket index pattern

Tiny worked example

  • On a 12-hour clock, 14 o'clock behaves like 2 o'clock because `14 ≡ 2 (mod 12)`.
  • In hashing, keys with the same remainder mod the bucket count land in the same bucket.
  • That is modular arithmetic showing up in software practice.

Common mistakes

How to recognize this kind of problem

Start practice