Challenge - 5 Problems
Modular Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Modular Addition
What is the output of this Go code that performs modular addition?
DSA Go
package main import "fmt" func main() { const mod = 7 a := 5 b := 6 result := (a + b) % mod fmt.Println(result) }
Attempts:
2 left
💡 Hint
Remember modular addition means adding then taking remainder with mod.
✗ Incorrect
5 + 6 = 11, 11 % 7 = 4, so output is 4.
❓ Predict Output
intermediateModular Multiplication Result
What does this Go code print after modular multiplication?
DSA Go
package main import "fmt" func main() { const mod = 10 a := 4 b := 3 result := (a * b) % mod fmt.Println(result) }
Attempts:
2 left
💡 Hint
Multiply first, then take remainder with mod.
✗ Incorrect
4 * 3 = 12, 12 % 10 = 2, so output is 2.
🧠 Conceptual
advancedModular Inverse Existence
Which condition must be true for a modular inverse of a number 'a' modulo 'm' to exist?
Attempts:
2 left
💡 Hint
Think about when division modulo is possible.
✗ Incorrect
A modular inverse exists only if 'a' and 'm' share no common divisors other than 1.
❓ Predict Output
advancedOutput of Modular Exponentiation
What is the output of this Go code performing modular exponentiation?
DSA Go
package main import "fmt" func modExp(base, exp, mod int) int { result := 1 b := base % mod e := exp for e > 0 { if e%2 == 1 { result = (result * b) % mod } b = (b * b) % mod e /= 2 } return result } func main() { fmt.Println(modExp(3, 4, 5)) }
Attempts:
2 left
💡 Hint
Calculate 3^4 mod 5 step by step.
✗ Incorrect
3^4 = 81, 81 % 5 = 1, but careful with code steps.
🧠 Conceptual
expertWhy Use Modular Arithmetic in Algorithms?
Why do many algorithms use modular arithmetic when working with large numbers?
Attempts:
2 left
💡 Hint
Think about computer memory limits and number size.
✗ Incorrect
Modular arithmetic keeps numbers small and manageable, preventing overflow.
