Blame | Last modification | View Log | Download | RSS feed
def Extended_Euclidian(a, b):''' Takes values a and b and returns a tuple (r,s,t) in the following format:r = s * a + t * b where r is the GCD and s and t are the inverses of a and b '''t_ = 0t = 1s_ = 1s = 0q = int(a/b)r = a - q * bprint("%d\t= %d * %d + %d" % (a, q, b, r))while r > 0:temp = t_ - q * tt_ = tt = temptemp = s_ - q * ss_ = ss = tempa = bb = rq = int(a/b)r = a - q * bprint("%d\t= %d * %d + %d" % (a, q, b, r))r = breturn (r, s, t)if __name__ == '__main__':a = 99b = 101res = Extended_Euclidian(a, b)print("%d = %d * %d + %d * %d" % (res[0], res[1], a, res[2], b))