Euclid repeatedly replaces a pair with the divisor and remainder. Because every common divisor of the original pair also divides the remainder, the GCD is preserved at each line. The strictly smaller non-negative remainder guarantees termination.
Example: gcd(180,48)
The equations are 180=3×48+36, 48=1×36+12 and 36=3×12+0. The last non-zero remainder is 12, so gcd(180,48)=12.
Zero is an explicit base case
When the second magnitude is zero, the first magnitude is already the GCD. Therefore gcd(a,0)=abs(a), including gcd(0,0)=0 under this product convention.
Verify the arithmetic and its context
GCDLCM checks divisibility identities before returning a result, but an exact arithmetic answer does not prove that a real-world plan, interval, component, structure, dose, route, machine, or safety decision is suitable. Reproduce important results independently and apply only the rules of the neutral integer problem you actually intend to solve.