2609번 : 최대공약수와 최소공배수 - Python

Pobi·2023년 2월 5일
0

PS

목록 보기
38/107

문제

https://www.acmicpc.net/problem/2609

풀이

유클리드 호제법을 이용하여 두 수의 최대공약수를 구한다음, 두수의 곱 = 최대공약수 * 최소공배수라는 공식을 이용하여 풀면 된다.

코드

from sys import stdin

input = stdin.readline
    
a, b = map(int, input().split())    

def gcd(a, b):
    if(b>a) : a,b = b,a

    while(b!=0):
        a=a%b
        a,b=b,a
        
    return a

g = gcd(a,b)

print(g)
print(a*b//g)
profile
꿈 많은 개발자

0개의 댓글