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 the following C# code that performs modular addition?
DSA C#
int a = 17; int b = 23; int mod = 10; int result = (a + b) % mod; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Remember to add first, then take the remainder with the modulus.
✗ Incorrect
The sum is 17 + 23 = 40. Taking 40 % 10 gives 0, so the correct output is 0.
❓ Predict Output
intermediateModular Multiplication Result
What will be printed after running this C# code snippet that uses modular multiplication?
DSA C#
int x = 7; int y = 8; int mod = 12; int result = (x * y) % mod; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Multiply first, then apply the modulus operator.
✗ Incorrect
7 * 8 = 56. Then 56 % 12 = 8, so output should be 8.
❓ Predict Output
advancedModular Exponentiation Output
What is the output of this C# code that calculates modular exponentiation?
DSA C#
int baseNum = 3; int exponent = 4; int mod = 5; int result = 1; for (int i = 0; i < exponent; i++) { result = (result * baseNum) % mod; } Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Calculate 3^4 mod 5 step by step.
✗ Incorrect
3^4 = 81. 81 % 5 = 1, but let's check the loop calculation carefully.
Step 1: result=1*3=3 %5=3
Step 2: 3*3=9 %5=4
Step 3: 4*3=12 %5=2
Step 4: 2*3=6 %5=1
Final result is 1.
❓ Predict Output
advancedModular Inverse Calculation
What is the output of this C# code that tries to find the modular inverse of 3 modulo 11 using brute force?
DSA C#
int a = 3; int mod = 11; int inverse = -1; for (int x = 1; x < mod; x++) { if ((a * x) % mod == 1) { inverse = x; break; } } Console.WriteLine(inverse);
Attempts:
2 left
💡 Hint
Find x such that (3 * x) % 11 == 1.
✗ Incorrect
Check multiples of 3 mod 11: 3*7=21 %11=10, no; 3*4=12 %11=1, yes.
Actually, 3*4=12 %11=1, so inverse is 4.
🧠 Conceptual
expertProperties of Modular Arithmetic
Which of the following statements about modular arithmetic is FALSE?
Attempts:
2 left
💡 Hint
Consider the meaning of negative exponents in modular arithmetic.
✗ Incorrect
Modular arithmetic properties hold for addition, subtraction, and multiplication.
However, exponentiation with negative exponents requires modular inverse, which may not exist.
So statement A is false.
