Last active
October 11, 2018 12:48
-
-
Save Francis-Lee-Earth/49c06d6eb77805d7d8971300967ffb1c to your computer and use it in GitHub Desktop.
Greatest Common Divisor (GCD)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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