Skip to content

Instantly share code, notes, and snippets.

@wang-zhijun
Last active March 16, 2016 13:49
Show Gist options
  • Save wang-zhijun/7888852 to your computer and use it in GitHub Desktop.
Save wang-zhijun/7888852 to your computer and use it in GitHub Desktop.
Pythonでgcdを計算
#!/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
@wang-zhijun
Copy link
Author

from fractions import gcd
gcd(20,8)
4
import inspect
print inspect.getsource(gcd) # ソースコード出てくる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment