Modular arithmetic is a way of doing math where numbers wrap around after reaching a certain value called the modulus. Think of a clock where after 12 comes 1 again.
Click to reveal answer
beginner
What does the expression a % m mean in modular arithmetic?
It means the remainder when a is divided by m. For example, 17 % 5 = 2 because 17 divided by 5 leaves remainder 2.
Click to reveal answer
beginner
How do addition and multiplication work in modular arithmetic?
You add or multiply numbers normally, then take the remainder after dividing by the modulus. For example, if modulus is 5, then (3 + 4) % 5 = 2 and (3 * 4) % 5 = 2.
Click to reveal answer
intermediate
Why is modular arithmetic useful in programming?
It helps keep numbers within a fixed range, avoids overflow, and is used in hashing, cryptography, and algorithms that need wrap-around behavior.
Click to reveal answer
intermediate
What is the result of (a - b) % m if a < b?
In modular arithmetic, (a - b) % m wraps around and stays non-negative by adding m if needed. For example, with a=2, b=5, m=7, (2 - 5) % 7 = 4.
Click to reveal answer
What is 10 % 3?
A3
B2
C0
D1
✗ Incorrect
10 divided by 3 leaves remainder 1.
If modulus is 6, what is (4 + 5) % 6?
A5
B9
C3
D1
✗ Incorrect
Sum is 9, and 9 % 6 = 3.
Which operation is NOT valid directly in modular arithmetic?
ADivision
BMultiplication
CAddition
DSubtraction
✗ Incorrect
Division is tricky and not always possible in modular arithmetic without special methods.
What does modular arithmetic help prevent in programming?
ASyntax errors
BNumber overflow
CSlow execution
DMemory leaks
✗ Incorrect
Modular arithmetic keeps numbers within a fixed range, preventing overflow.