Modular arithmetic is "clock math" β numbers wrap around after reaching a certain value called the modulus. It's the single most powerful tool in number theory. Once you think in terms of remainders, divisibility rules, last-digit problems, and cyclic patterns all become trivial. Master the basics here, then we'll go deep.
We say $a$ is congruent to $b$ modulo $m$ if $m$ divides $(a - b)$.
\[ a \equiv b \pmod{m} \quad \Longleftrightarrow \quad m \mid (a - b) \]
Intuitively: a and b leave the same remainder when divided by m.
Examples:
If $ a \equiv b \pmod{m} $ and $ c \equiv d \pmod{m} $, then:
Important: Division doesn't always work! You can only divide both sides by k if gcd(k, m) = 1. We'll cover modular inverses for this.
Any integer can be reduced to its residue β the unique remainder r where $ 0 \leq r < m $.
To find a mod m: divide by m, take the positive remainder.
For negative numbers: add multiples of m until you get into [0, m).
Example: -3 mod 7 = -3 + 7 = 4. So $ -3 \equiv 4 \pmod{7} $.
The last digit of a number is just the number mod 10.
Last digits of powers cycle! For example, powers of 2:
Cycle length = 4. So \(2^{n}\) last digit depends on n mod 4.
Since $ 10 \equiv 0 \pmod{2} $ and $ 10 \equiv 0 \pmod{5} $, only the last digit matters for divisibility by 2 or 5.
Since $ 10 \equiv 1 \pmod{3} $ and $ 10 \equiv 1 \pmod{9} $, we have $ 10^k \equiv 1^k = 1 \pmod{3} $. So a number equals the sum of its digits mod 3 (and mod 9).
Since $ 10 \equiv -1 \pmod{11} $, we have $ 10^k \equiv (-1)^k \pmod{11} $. This gives the alternating-sum rule for 11.
Modular arithmetic is the proof behind every divisibility rule!
Modulo m, there are exactly m distinct residue classes: {0, 1, 2, ..., m-1}.
Every integer belongs to exactly one class. Two numbers in the same class are congruent mod m.
The set $ \mathbb{Z}/m\mathbb{Z} = \{0, 1, 2, ..., m-1\} $ is the set of residues mod m.
To compute $ a^n \pmod{m} $ efficiently, you can reduce at each step:
Key idea: you never need to deal with huge numbers. Reduce after every multiplication.
$ ax \equiv b \pmod{m} $ has a solution iff gcd(a, m) divides b.
If gcd(a, m) = 1, there's exactly one solution mod m (found via modular inverse).
If gcd(a, m) = d > 1 and d | b, there are d solutions mod m.
If d doesn't divide b, no solution.
Last digit = number mod 10. Find the cycle of 3^n mod 10.
Step 1: Compute powers of 3 mod 10.
\((3^{1} = 3 mod 10 \\to\) 3\)
\((3^{2} = 9 mod 10 \\to\) 9\)
\((3^{3} = 27 mod 10 \\to\) 7\)
\((3^{4} = 81 mod 10 \\to\) 1\)
\((3^{5} = 243 mod 10 \\to\) 3 (cycle repeats!)\)
Step 2: Cycle length = 4.
Step 3: Reduce exponent mod cycle length.
25 Γ· \(4 = 6 remainder 1, so 25 \\equiv 1 (mod 4)\)
Step 4: \((3^{2}^\){5} \\equiv 3^{1} \\equiv 3 (mod 10)\)
Last digit is 3.
Answer: 3
Method 1: Direct division
\(7 \\times 19 = 133\)
137 - 133 = 4
\(So 137 = 7 \\times 19 + 4, remainder = 4.\)
Method 2: Reduce step by step (useful for larger numbers)
\(137 \\to 137 - 70 = 67 \\to 67 - 70 = -3 \\to -3 + 7 = 4\)
Same answer.
Method 3: Digit tricks
\(Since 10 \\equiv 3 mod 7: 137 = 1 \\times 10^{2} + 3 \\times 10 + 7 \\equiv 1 \\times 9 + 3 \\times 3 + 0 \\equiv 9 + 9 \\equiv 18 \\equiv 4 mod 7\) β
Answer: 4
\(We need 3x \\equiv 1 (mod 7). We're finding the modular inverse of 3 mod 7.\)
Method: Try residues 0 through 6.
\(x = 0: 3 \\times 0 = 0 \\equiv 0 \\neq 1\) β
\(x = 1: 3 \\times 1 = 3 \\equiv 3 \\neq 1\) β
\(x = 2: 3 \\times 2 = 6 \\equiv 6 \\neq 1\) β
\(x = 3: 3 \\times 3 = 9 \\equiv 2 \\neq 1\) β
\(x = 4: 3 \\times 4 = 12 \\equiv 5 \\neq 1\) β
\(x = 5: 3 \\times 5 = 15 \\equiv 1\) β
Step 2: \(Verify: 3 \\times 5 = 15, and 15 - 1 = 14, which is divisible by 7.\) β
x = 5 is the smallest positive solution.
Note: since gcd(3, 7) = 1, there's exactly one solution mod 7.
Answer: 5