Data Structures & AlgorithmsHardCodeforces Div2 B · modular inverse

Problem: What does the following print? It is the multiplicative inverse of 7 modulo 26.

Problem: What does the following print? It is the multiplicative inverse of 7 modulo 26.
print(pow(7, -1, 26))
  1. A. 15
  2. B. 11
  3. C. 19
  4. D. 23

Correct answer: A. 15

7 * 15 = 105 = 4 * 26 + 1, so 15 is the inverse. The inverse exists only because gcd(7, 26) = 1, and 11 is the trap that results from a sign slip.

More Coding Interview Problems questions

Exams that ask this topic