ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
def fermat_inverse(a, p):
    return pow(a, p - 2, p)
print(fermat_inverse(3, 7) == pow(3, -1, 7), 3 * fermat_inverse(3, 7) % 7, (-3) * fermat_inverse(3, 7) % 7, (-3 * fermat_inverse(3, 7)) % 7)
  1. A. True 1 1 6
  2. B. True 1 6 6
  3. C. False 1 6 6
  4. D. True 0 6 6

Correct answer: B. True 1 6 6

For a prime p, a**(p-2) is the inverse of a, and 3 inverse mod 7 is 5. Multiplying by -3 and reducing with Python's % gives 6, the non-negative remainder.

More Python Programming questions

Exams that ask this topic