Greatest common divisor
Return the nonnegative greatest common divisor of two integers. Define gcd(0,0) as zero.
a, b = 48, 18
a, b = b, a % b
print(a, b)Reason about the state
Euclid replaces the pair by divisor and remainder until the remainder vanishes. Taking absolute values handles signs consistently. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the nonnegative greatest common divisor of two integers. Define gcd(0,0) as zero.
The explanation opens here once every check passes.