Recall & Review
beginner
What is modular arithmetic?
Modular arithmetic is a way of doing math where numbers wrap around after reaching a certain value called the modulus. It's like a clock where after 12, it goes back to 1.
Click to reveal answer
beginner
What does the expression
a % m mean?It means the remainder when number
a is divided by m. For example, 7 % 3 = 1 because 7 divided by 3 leaves remainder 1.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?Even if
a is less than b, (a - b) % m gives a non-negative remainder by wrapping around. For example, with m=5, (2 - 3) % 5 = 4.Click to reveal answer
What is the value of
10 % 4?✗ Incorrect
10 divided by 4 is 2 with remainder 2, so 10 % 4 = 2.
If modulus is 7, what is
(5 + 6) % 7?✗ Incorrect
5 + 6 = 11, and 11 % 7 = 4.
Which of these is true for modular multiplication?
✗ Incorrect
Modular multiplication distributes over modulus: multiply remainders then take modulus again.
What happens if you do
(a - b) % m and a < b?✗ Incorrect
Modular arithmetic wraps negative results to positive by adding modulus.
Why is modular arithmetic like a clock?
✗ Incorrect
Like a clock resets after 12, modular arithmetic resets numbers after modulus.
Explain modular arithmetic and how addition works with an example.
Think about how a clock resets after 12 hours.
You got /4 concepts.
Describe why modular arithmetic is important in programming and give two examples of its use.
Consider situations where numbers must wrap around or stay small.
You got /4 concepts.