Skip to content

Instantly share code, notes, and snippets.

@Francis-Lee-Earth
Last active October 11, 2018 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Francis-Lee-Earth/49c06d6eb77805d7d8971300967ffb1c to your computer and use it in GitHub Desktop.
Save Francis-Lee-Earth/49c06d6eb77805d7d8971300967ffb1c to your computer and use it in GitHub Desktop.
Greatest Common Divisor (GCD)
def greatest_common_divisor(a, b):
"""
除非 b == 0,否則結果將與 b 具有相同的正負號
(因此,當 b 除以它,結果是正號)
"""
while b > 0:
a, b = b, a % b
return a
g = greatest_common_divisor(120 , 23)
print(g)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment