Modular Arithmetic
Operations & Congruences
Master the clock arithmetic that powers cryptography, computer science, and number theory: from congruence notation to modular operations.
What Is Modular Arithmetic?
Modular arithmetic is a system where integers "wrap around" after reaching a fixed value called the modulus. Think of a clock: after \( 12 \), we go back to \( 1 \), not \( 13 \).
Formally, \( a \equiv b \pmod{n} \) means \( n \mid (a - b) \): the modulus \( n \) divides the difference \( a - b \) evenly.
The Clock Analogy
Why Modular Arithmetic Matters
From checking credit card numbers (Luhn algorithm) to securing online banking, modular arithmetic is everywhere in the modern world.
Formal Congruence Definition
Properties of Congruence
Congruence modulo \( n \) is an equivalence relation satisfying three properties:
Arithmetic Operations mod \( n \)
If \( a \equiv b \pmod{n} \) and \( c \equiv d \pmod{n} \), then:
Modular Exponentiation
This lets us reduce the base before raising to a power, avoiding enormous numbers:
Operator vs Relation
Students often confuse two uses of "mod." They are related but fundamentally different:
| \( a \bmod n \) (Operator) | \( a \equiv b \pmod{n} \) (Relation) | |
|---|---|---|
| Type | Returns a number | Returns true or false |
| Example | \( 17 \bmod 5 = 2 \) | \( 17 \equiv 2 \pmod{5} \) |
| Range | \( 0 \le r < n \) | Both sides: any integer |
| Use case | Computing remainders | Proving relationships |
The Division Caveat
Addition, subtraction, and multiplication work seamlessly. But division is dangerous:
How to Compute Step by Step
Example: Addition & Multiplication
Compute \( (23 + 19) \cdot 7 \pmod{10} \).
Example: Repeated Squaring
Compute \( 3^{13} \pmod{7} \) using repeated squaring.
Example: Negative Numbers mod \( n \)
What is \( -17 \bmod 5 \)?
Residue Classes mod \( 5 \)
Common Mistakes
Summary of Operations
| Operation | Rule | Condition |
|---|---|---|
| Addition | \( (a + b) \bmod n \) | Always valid |
| Subtraction | \( (a - b) \bmod n \) | Always valid |
| Multiplication | \( (a \cdot b) \bmod n \) | Always valid |
| Exponentiation | \( a^k \bmod n \) | Always valid |
| Division | \( a \cdot b^{-1} \bmod n \) | \( \gcd(b, n) = 1 \) |
Question 1 of 5
What is \( 47 \bmod 7 \)?
Question 2 of 5
If \( a \equiv 3 \pmod{7} \) and \( b \equiv 5 \pmod{7} \), what is \( a \cdot b \pmod{7} \)?
Question 3 of 5
What is \( -11 \bmod 4 \)?
Question 4 of 5
Which statement about dividing in modular arithmetic is correct?
Question 5 of 5
Compute \( 2^{10} \pmod{11} \).