算法原理
Python代码
def myExtGCD(a, b):
"""
a: 模的取值
b: 想求逆的值
"""
if (b == 0):
return 1, 0, a
x, y, gcd = myExtGCD(b, a % b)
return y, x-a//b*y, gcd
print(myExtGCD(71, 7)[1] % 71)
def myExtGCD(a, b):
"""
a: 模的取值
b: 想求逆的值
"""
if (b == 0):
return 1, 0, a
x, y, gcd = myExtGCD(b, a % b)
return y, x-a//b*y, gcd
print(myExtGCD(71, 7)[1] % 71)