Challenge - 5 Problems
Modular Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Modular Addition
What is the output of the following Python code that performs modular addition?
DSA Python
a = 17 b = 23 mod = 10 result = (a + b) % mod print(result)
Attempts:
2 left
💡 Hint
Add the numbers first, then find the remainder when divided by 10.
✗ Incorrect
Adding 17 + 23 gives 40. Taking 40 modulo 10 means finding the remainder when 40 is divided by 10, which is 0.
❓ Predict Output
intermediate2:00remaining
Modular Multiplication Result
What will be printed by this code that calculates modular multiplication?
DSA Python
x = 7 y = 5 mod = 12 product = (x * y) % mod print(product)
Attempts:
2 left
💡 Hint
Multiply first, then take remainder with 12.
✗ Incorrect
7 times 5 is 35. 35 modulo 12 is 11 because 12 * 2 = 24 and 35 - 24 = 11.
🧠 Conceptual
advanced2:00remaining
Understanding Modular Inverse
Which of the following statements correctly describes the modular inverse of a number 'a' modulo 'm'?
Attempts:
2 left
💡 Hint
Think about what multiplying by the inverse should do under modulo.
✗ Incorrect
The modular inverse of 'a' modulo 'm' is a number 'x' that when multiplied by 'a' gives 1 modulo 'm'. This means (a * x) % m = 1.
❓ Predict Output
advanced2:00remaining
Output of Modular Exponentiation
What is the output of this code that calculates modular exponentiation?
DSA Python
base = 4 exponent = 13 mod = 497 result = pow(base, exponent, mod) print(result)
Attempts:
2 left
💡 Hint
Use Python's built-in pow with three arguments for efficient modular exponentiation.
✗ Incorrect
Using pow(4, 13, 497) computes (4^13) mod 497 efficiently, which equals 445.
🔧 Debug
expert2:00remaining
Identify the Error in Modular Division Code
What error will this code raise when trying to perform modular division?
DSA Python
a = 10 b = 3 mod = 7 result = (a // b) % mod print(result)
Attempts:
2 left
💡 Hint
Modular division requires multiplying by modular inverse, not integer division.
✗ Incorrect
The code uses integer division (//) which does not work for modular division. It will produce a wrong output, not an error.