https://programmers.co.kr/learn/courses/30/lessons/12940
νμ΄
# νλ‘κ·Έλλ¨Έμ€ 1λ¨κ³ - μ΅λ곡μ½μμ μ΅μ곡배μ
import math
def lcm(a,b):
return (a * b) // math.gcd(a,b)
def solution(a, b):
c = math.gcd(a,b)
d = lcm(a,b)
answer = [c,d]
return answer
print(solution(2,5))
λ΄μ₯ ν¨μμΈ gcd μ lcmμ μ¬μ©νλ €κ³ νμΌλ lcmμ΄ μ¬μ©ν μ μμ΄μ λ°λ‘ ν¨μλ₯Ό λ§λ€μ΄ μ£Όμλ€.
λ΄μ₯ ν¨μλ₯Ό μ¬μ©νμ§ μμ νμ΄
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