Complete the code to compute the remainder of 17 divided by 5.
int result = 17 [1] 5;
/ instead of modulo.The modulo operator % gives the remainder of division. Here, 17 % 5 equals 2.
Complete the code to compute (a + b) modulo m correctly.
int modSum = (a [1] b) % m;To add two numbers under modulo, add them first then take modulo. So use + operator inside parentheses.
Fix the error in the code to compute (a * b) modulo m without overflow.
long long modProduct = ((long long)a [1] b) % m;long long causing overflow.To multiply two integers safely without overflow, cast one to long long and use the multiplication operator *.
Fill both blanks to compute (a - b) modulo m correctly, ensuring the result is non-negative.
int modDiff = ((a [1] b) [2] m) % m;
m after subtraction causing negative modulo.Subtract b from a, then add m before taking modulo to avoid negative results.
Fill all three blanks to create a map of numbers to their squares modulo m for numbers 1 to 5.
std::map<int, int> squares; for (int [1] = 1; [1] <= 5; ++[1]) { squares[[1]] = ([2] [3] [2]) % m; }
Use i as the key and value base, multiply i * i then take modulo m.
