Recursive Version

def extended_gcd(a, b):
    if b == 0:
        return a, 1, 0
    else:
        gcd, x1, y1 = extended_gcd(b, a % b)
        x = y1
        y = x1 - (a // b) * y1
        return gcd, x, y

Non-recursive Version

def ex_gcd(a, b):
    x, y = 1, 0
    x1, y1 = 0, 1
    a1, b1 = a, b
 
    while b1 != 0:
        q = a1 // b1
        a1, b1 = b1, a1 - q * b1
        x, x1 = x1, x - q * x1
        y, y1 = y1, y - q * y1
 
    return a1, x, y

Calculation by Hand

For example, calculate

010810
1086801
68401-1
4028-12
28122-3
124-58
40
this gives