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)- A. True 1 1 6
- B. True 1 6 6
- C. False 1 6 6
- 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
- What is printed? python print(sorted(['beta', 'Alpha', 'alpha', 'Beta'], key=str.lower))
- What is printed? python x = 0.1 + 0.7 print(x, x 10, int(x 10), round(x 10))
- What is printed? python print(int('3' 3) + int('4' 2) 2, '3' 3 + '4' 2 2)
- What is printed? python print(len('%s' % 1.0), len('%g' % 1.0), len(repr(1.0)), str(1e5), '%g' % 1e5, '%g' % 1e6)
- What is printed? python def f(s): return s[::-1] == s print(f('abba'), f('ab' 2), f(''), f('a'))
- What is printed? python print(True + True, str(True) + '1', str(None), str([None]), repr('None'))