ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(pow(2, -1, 10 ** 9 + 7))
  1. A. 500000004
  2. B. -500000003
  3. C. 1000000006
  4. D. 5

Correct answer: A. 500000004

Since Python 3.8 pow(a, -1, m) gives the modular inverse when it exists. The inverse of 2 modulo p = 10^9+7 is (p + 1) / 2 = 500000004, because 2 * 500000004 = p + 1 leaves remainder 1.

More Python Programming questions

Exams that ask this topic