Bird
0
0
DSA Cprogramming~20 mins

Modular Arithmetic Basics in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modular Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Modular Addition
What is the output of the following C code snippet that performs modular addition?
DSA C
int a = 17;
int b = 23;
int mod = 10;
int result = (a + b) % mod;
printf("%d\n", result);
A1
B0
C10
D9
Attempts:
2 left
💡 Hint
Remember that modular addition sums the numbers and then takes the remainder after division by the modulus.
Predict Output
intermediate
2:00remaining
Modular Multiplication Result
What will be printed by this C code that calculates modular multiplication?
DSA C
int x = 7;
int y = 8;
int mod = 5;
int product = (x * y) % mod;
printf("%d\n", product);
A2
B6
C0
D1
Attempts:
2 left
💡 Hint
Multiply first, then take the remainder after dividing by the modulus.
🧠 Conceptual
advanced
2:00remaining
Properties of Modular Arithmetic
Which of the following statements about modular arithmetic is FALSE?
AModular multiplication is distributive over addition: (a * (b + c)) mod m = ((a * b) mod m + (a * c) mod m) mod m
BModular addition is associative: (a + b) mod m = ((a mod m) + (b mod m)) mod m
CModular subtraction always produces a positive result
DFor any integer a, (a mod m) is always between 0 and m-1 inclusive
Attempts:
2 left
💡 Hint
Think about what happens when subtracting a larger number from a smaller one in modular arithmetic.
Predict Output
advanced
2:00remaining
Modular Exponentiation Output
What is the output of this C code that calculates modular exponentiation using a simple loop?
DSA C
int base = 3;
int exponent = 4;
int mod = 5;
int result = 1;
for (int i = 0; i < exponent; i++) {
    result = (result * base) % mod;
}
printf("%d\n", result);
A1
B2
C3
D4
Attempts:
2 left
💡 Hint
Calculate 3^4 first, then take modulo 5.
🧠 Conceptual
expert
2:00remaining
Modular Inverse Existence
Which condition must be true for an integer 'a' to have a modular inverse modulo 'm'?
A'a' and 'm' are coprime (their greatest common divisor is 1)
B'a' is less than 'm'
C'm' is a prime number
D'a' is an even number
Attempts:
2 left
💡 Hint
Think about when division modulo 'm' is possible.