Extended Euclidean algorithm
Find the GCD and two numbers that express it. For example, 48 × (−1) + 18 × 3 = 6.
From each entry of row u subtract q times the entry below it in row v. The first column gives the remainder, the other two give its coefficients.
When row v has remainder zero, row u holds the answer.
The division count matches Euclid’s GCD algorithm. For positive inputs it grows logarithmically. Three rows suffice.