Last active
March 16, 2016 13:49
-
-
Save wang-zhijun/7888852 to your computer and use it in GitHub Desktop.
Pythonで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
#!/usr/bin/env python | |
def gcd(a, b): | |
"""Calculate the Greatest Common Divisor of a and b. | |
Unless b==0, the result will have the same sign as b (so that when | |
b is divided by it, the result comes out positive). | |
""" | |
while b: | |
a, b = b, a%b | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from fractions import gcd
gcd(20,8)
4
import inspect
print inspect.getsource(gcd) # ソースコード出てくる