파이썬 gcd()

(Python gcd()에서 넘어옴)

1 개요[ | ]

Python gcd()
파이썬 gcd()
Python
CPU
0.0s
MEM
8M
0.1s
Copy
from math import gcd
print( gcd(20,8) ) # 4
print( gcd(12,21) ) # 3
4
3
Python
Copy
def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a

print( gcd(12,21) ) # 3
print( gcd(20,8) ) # 4
Loading

2 같이 보기[ | ]