Last active
November 26, 2021 06:52
-
-
Save b3z/d55d8345ccd02785f792384fa3b637a7 to your computer and use it in GitHub Desktop.
Multiplicative inverse element modulo n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def euka(a, b): | |
u, v, s, t = 1, 0, 0, 1 | |
while b!=0: | |
q=a//b | |
a, b = b, a-q*b | |
u, s = s, u-q*s | |
v, t = t, v-q*t | |
return a, u, v | |
def modinverse(a, n): | |
g, u, v = euka(a, n) | |
return u%n | |
# print(modinverse(a, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment