Inputs
Any integer.
Any integer.
Try
Result
Undefined
gcd(0, 0) is undefined. Every integer divides 0, so 0 and 0 share infinitely many
common divisors with no greatest one — the standard definition of gcd has no answer
here. (Some software returns 0 for this input by convention, but that's a different,
more permissive definition — not this one.)
gcd(240, 46)
2
240 · (-9) + 46 · (47) = 2
- x
- -9
- y
- 47
- Steps
- 5
Algorithm steps
| i | q | r | x | y |
|---|
Every row satisfies r = a·x + b·y, working from |a| and |b|. The last nonzero r is gcd(a, b); its x and y (sign-adjusted for negative inputs) are the Bézout coefficients above.