Predict the output
What does this print?
m = 1_000_000_007
b = 4
inv = pow(b, m - 2, m)
print(b * inv % m, (12 * inv) % m, (-3) % m)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 1 3 1000000004
Right: inv is 4's inverse, 12 / 4 = 3, and Python's % keeps the result non-negative.
Division under a prime modulus becomes multiplication by an inverse, computed in O(log m) with three-argument pow.
Why not the others?
- B 1 3 -3. Python's % with a positive modulus never returns a negative number.
- C 4 12 1000000004. Multiplying by the inverse undoes the multiplication by 4.