Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. import sys
  2.  
  3. def egcd(a, b):
  4. if a == 0:
  5. return (b, 0, 1)
  6. else:
  7. g, x, y = egcd(b % a, a)
  8. return (g, y - (b // a) * x, x)
  9.  
  10. def mulinv(b, n):
  11. g, x,_= egcd(b, n)
  12. if g == 1:
  13. return x%n
  14. else:
  15. return -1
  16.  
  17. n,a=map(int,input().split())
  18. print(mulinv(a,n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement