Pastebin

Paste #602: extended euclid

< previous paste - next paste>

Pasted by tdn

Download View as text

# Extended Euclid

def extended_gcd(a, b):
    x = 0
    y = 0
    lastx = 1
    lasty = 0
    while b <> 0:
        tmp = b
        quotient = a/b
        b = a % b
        a = tmp
        tmp = x
        x = lastx-quotient*x
        lastx = tmp
        tmp = y
        y = lasty-quotient*y
        lasty = tmp
        #print (x,y,lastx,lasty,tmp,a,b,quotient)
    return (lastx, lasty, a)

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.