Find the gcd of a and b using Euclid's algorithm . When after some steps using this algorithm
and
b' = ua + vb
for certain integers x, y, u and v, then after the next step
and
b' = (xa + yb) - q(ua + vb)
= (x - qu)a + (y - qv)b,
where q is the quotient of a' and b'. Since Euclid's algorithm will eventually return a' as the gcd of a and b, the extended Euclidean algorithm will give x and y with gcd(a,b) = xa + yb.