ProgrammingVery hardGATE CS & IT · Infosys

What is printed?

What is printed?
print(pow(2, 100, 97), 2 ** 100 % 97, (-2) ** 3 % 5, pow(-2, 3, 5))
  1. A. 16 16 2 2
  2. B. 16 16 -3 2
  3. C. 16 16 3 -3
  4. D. 15 16 2 2

Correct answer: A. 16 16 2 2

Fermat's little theorem gives 2^96 = 1 mod 97, so 2^100 = 2^4 = 16. Python's % and three-argument pow return values from 0 to m-1, so -8 % 5 is 2.

More Python Programming questions

Exams that ask this topic