Modular arithmetic is a system of arithmetic for integers where numbers "wrap around" after reaching a certain value called the modulus.
Key Concepts:
- • Modulo Operation: a mod n gives the remainder when a is divided by n
- • Congruence: a ≡ b (mod n) means a and b have the same remainder
- • Euclidean Division: a = q × n + r, where 0 ≤ r < |n|
- • Clock Arithmetic: Time calculations use modulo 12 or 24
Applications:
- • Computer Science: Hash functions, array indexing
- • Cryptography: RSA encryption, digital signatures
- • Number Theory: Prime testing, factorization
- • Calendar Systems: Day of week calculations
- • Music Theory: Note intervals and octaves
Properties:
- • (a + b) mod n = ((a mod n) + (b mod n)) mod n
- • (a × b) mod n = ((a mod n) × (b mod n)) mod n
- • If a ≡ b (mod n), then a + c ≡ b + c (mod n)
- • If a ≡ b (mod n), then ac ≡ bc (mod n)
Common Uses:
- • Check if a number is even: n mod 2 = 0
- • Cycle through array indices: (i + 1) mod length
- • Convert 24-hour to 12-hour time: hour mod 12
- • Find last digit: number mod 10