Skip to content
4 changes: 4 additions & 0 deletions maths/greatest_common_divisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def greatest_common_divisor(a: int, b: int) -> int:
3
>>> greatest_common_divisor(-3, -9)
3
>>> greatest_common_divisor(0, 0)
0
"""
return abs(b) if a == 0 else greatest_common_divisor(b % a, a)

Expand All @@ -50,6 +52,8 @@ def gcd_by_iterative(x: int, y: int) -> int:
1
>>> gcd_by_iterative(11, 37)
1
>>> gcd_by_iterative(0, 0)
0
"""
while y: # --> when y=0 then loop will terminate and return x as final GCD.
x, y = y, x % y
Expand Down