Modular Arithmetic
Modular Arithmetic
MODULAR ARITHMETIC
• Modular arithmetic is a system of
arithmetic for integers where numbers
wrap around upon reaching a certain
value, known as the modulus. It’s
commonly described as “clock
arithmetic” because it mirrors how
hours wrap around on a clock (e.g.,
after 12 o'clock comes 1 o'clock)
MODULAR ARITHMETIC
Key Concept
• Modulo Operation:
For integers a and n (n > 0), the modulo operation a mod n finds the
remainder when a is divided by n.
a mod n = r where a = qn + r and 0 ≤ r < n
Example: 17 mod 5 = 2 17 mod 5 = 2 because 17 = 3⋅5 + 2.
• Congruence Relation : Two integers a and b are said to be
congruent modulo n if they have the same remainder when divided
by n
a ≡ b (mod n)⟺ n ∣(a−b)
Example: 17 ≡ 2 (mod 5) because both leave a remainder of 2 when
divided by 5.
Properties of Modular
Arithmetic
Addition
(a + b)mod n=[(a mod n)+(b mod n)]mod n
Example: (23 + 18) mod 7
1. Compute modulo for each number:
23 mod 7 = 2, 18mod 7 = 4
2. Add remainders:
2+4=6
3. Compute modulo again:
6 mod 7= 6
Final result: (23+18)mod 7=6
Properties of Modular
Arithmetic
Subtraction
(a - b)mod n=[(a mod n) - (b mod n)]mod n
Example: (23 - 18) mod 7
1. Compute modulo for each number:
23 mod 7 = 2, 18 mod 7 = 4
2. Subtract remainders:
2 - 4 = -2
3. Handle negative modulo:
Add 7 to make it positive: −2 + 7 = 5
Final result: (23 - 18) mod 7 = 5
Properties of Modular
Arithmetic
Multiplication
(a . b)mod n=[(a mod n) . (b mod n)]mod n
Example: (23 . 18) mod 7
1. Compute modulo for each number:
23 mod 7 = 2, 18 mod 7 = 4
2. multiply remainders:
2.4=8
3. Compute modulo again :
8 mod 7 = 1
Final result: (23 . 18) mod 7 = 1
•Cryptography: Algorithms like RSA rely
Applications
heavily on modular arithmetic.
•Hashing Functions: Used in
programming for distributing keys in hash
tables.
•Computer Science: In data structures
and algorithms, modular arithmetic often
simplifies calculations.
•Number Theory: Fundamental in
solving problems like Diophantine
equations.