programmers | Lv1. 최대공약수와 최소공배수 [Python]

yeonk·2022년 2월 23일
0

algorithm

목록 보기
39/88
post-thumbnail

💡 Python 3






🔗 문제

최대공약수와 최소공배수 [Link]






💻 코드

def solution(n, m):
    if n > m: n, m = m, n
    a, b = m, n
    while True:
        mod = a % b
        if mod == 0 : break
        a, b = b, mod
    return [b, m*n/b]






💥 다른 사람 코드

def gcdlcm(a, b):
    c, d = max(a, b), min(a, b)
    t = 1
    while t > 0:
        t = c % d
        c, d = d, t
    answer = [c, int(a*b/c)]

    return answer






참고 자료

[프로그래머스](python) 최대공약수와 최소공배수

[python] 프로그래머스 Level.1 최대공약수와 최소공배수

0개의 댓글