ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(pow(-2, 3, 5), pow(3, -1, 7), pow(2, 10, -7), (-2) ** 3 % 5)
  1. A. 2 5 2 2
  2. B. 2 5 -5 2
  3. C. 3 5 -5 2
  4. D. 2 4 -5 2

Correct answer: B. 2 5 -5 2

Three-argument pow with a negative modulus returns a result with the modulus's sign, and 1024 is 2 mod 7, so the result is 2 - 7 = -5. pow(3, -1, 7) is the inverse 5 because 3 * 5 = 15 is 1 mod 7, and (-8) % 5 is 2.

More Python Programming questions

Exams that ask this topic