Last active
February 14, 2018 14:31
-
-
Save linusheck/bd102b3b0158080305ed1404cdbf6fd6 to your computer and use it in GitHub Desktop.
This file contains 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
# usage: python xea.py <num1> <num2> | |
from sys import argv | |
pa, pb = int(argv[1]), int(argv[2]) | |
a, b = pa, pb | |
mods = [a, b] | |
mod = a % b | |
while mod != 0: | |
mods.append(mod) | |
a = b | |
b = mod | |
mod = a % b | |
xi = [1, 0] | |
yi = [0, 1] | |
for i in range(2, len(mods)): | |
xi.append(xi[i - 2] - (xi[i - 1] * int(mods[i - 2] / mods[i - 1]))) | |
yi.append(yi[i - 2] - (yi[i - 1] * int(mods[i - 2] / mods[i - 1]))) | |
print("ri =", mods) | |
print("xi =", xi) | |
print("yi =", yi) | |
print(xi[-1], "*", pa, "+", yi[-1], "*", pb, "=", end=" ") | |
print("gcd(" + str(pa) + ", " + str(pb) + ") = " + str(mods[-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment