Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def gcd(a,b):
- if a == 0:
- return (b,0,1)
- else:
- g, y, x = gcd(b % a ,a)
- return (g, x-(b//a)*y,y)
- def mod_inverse(a,m):
- g, x, y = gcd(a, m)
- if g != 1:
- raise Exception('Modular error')
- else:
- return x % m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement