mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
parent
e463c0b573
commit
e3d4d2bb57
|
@ -10,6 +10,16 @@ def greatest_common_divisor(a, b):
|
|||
Calculate Greatest Common Divisor (GCD).
|
||||
>>> greatest_common_divisor(24, 40)
|
||||
8
|
||||
>>> greatest_common_divisor(1, 1)
|
||||
1
|
||||
>>> greatest_common_divisor(1, 800)
|
||||
1
|
||||
>>> greatest_common_divisor(11, 37)
|
||||
1
|
||||
>>> greatest_common_divisor(3, 5)
|
||||
1
|
||||
>>> greatest_common_divisor(16, 4)
|
||||
4
|
||||
"""
|
||||
return b if a == 0 else greatest_common_divisor(b % a, a)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user