파이썬 gcd()

Jmnote (토론 | 기여)님의 2018년 7월 14일 (토) 21:37 판 (→‎개요)

1 개요

Python gcd()
파이썬 gcd()
from fractions import gcd
print( gcd(20,8) )
# 4
print( gcd(12,21) )
# 3
def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a

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

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}