ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
print(divmod(-17, 5), divmod(17, -5), -17 % -5, pow(3, -1, 7))
  1. A. (-3, -2) (-3, 2) -2 5
  2. B. (-4, 3) (-4, -3) -2 5
  3. C. (-4, 3) (-3, -2) -2 5
  4. D. (-4, 3) (-3, 2) -2 ValueError

Correct answer: B. (-4, 3) (-4, -3) -2 5

// floors toward minus infinity and % takes the sign of the divisor: -17 = 5*(-4) + 3 and 17 = (-5)*(-4) - 3. pow(3, -1, 7) is the modular inverse of 3 mod 7, which is 5 (3*5 = 15 = 1 mod 7).

More Python Programming questions

Exams that ask this topic