Algorithm/백준

[BAEKJOON] 2609번: 최대공약수와 최소공배수

NegotiationMan 2023. 8. 23. 11:16

문제

개의 자연수를 입력받아 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오.

 

코드

import sys, math
input = sys.stdin.readline

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

print(math.gcd(a,b), (a*b)//math.gcd(a,b), sep='\n')

 

나의 생각

찾아보니 최소공배수 구하는 함수도 math 모듈에 내장되어 있는데 3.9 버전 이상부터 사용 가능하다.

import sys, math
input = sys.stdin.readline

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

print(math.gcd(a,b), math.lcm(a,b), sep='\n')