CSSEXP2B
CSSEXP2B
2B
# Function to calculate the modular inverse of a under modulo m using Extended Euclidean Algorithm
def mod_inverse(a, m):
m0, x0, x1 = m, 0, 1
while a > 1:
q = a // m
m, a = a % m, m
x0, x1 = x1 - q * x0, x0
if x1 < 0:
x1 += m0
return x1
OUTPUT :