def bezout_ext(a, b):
    qs, rs = [], [a, b]
    while b > 0:
        q, r = divmod(a, b)
        print(f"{a} = {b} * {q} + {r}")
        qs.append(q)
        rs.append(r)
        a, b = b, a % b
    n = len(qs) - 3
    m = len(rs) - 3

    u, v = 1, -qs[-2]
    # res = [(u, rs[-4], v, rs[-3])]
    for i in range(n , -1, -1):
        u, v = v, u - qs[i] * v
        # res.append((u, rs[i], v, rs[i + 1]))
        print(f"{u} * {rs[i]} + {v} * {rs[i+1]} = {a}")
    return "ok"


r = bezout_ext(87, 79)
print(r)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: