ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(pow(2, -1, 10 ** 9 + 7))
- A. 500000004
- B. -500000003
- C. 1000000006
- 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
- What is printed? python import math n = 10 30 - 1 print(math.isqrt(n), int(n 0.5))
- What is printed? python print(2 53 + 1 == float(2 53 + 1))
- What is printed? python import io s = io.StringIO("abcn") print(repr(s.readline()), repr(s.readline()))
- What is printed? python data = "2n10 20n30n" it = iter(data.split()) n = int(next(it)) arr = [int(next(it)) for in range(n)] print(arr…
- What is printed? python from operator import itemgetter rows = [('b', 2, 'x'), ('a', 2, 'y'), ('c', 1, 'z')] print([r[0] for r in…
- What is printed? python import bisect print(bisect.bisect([1, 2, 2, 5], 2))