문제
두 개의 자연수를 입력받아 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오.
코드
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')'Algorithm > 백준' 카테고리의 다른 글
| [BAEKJOON] 1978번: 소수 찾기 (0) | 2023.08.23 |
|---|---|
| [BAEKJOON] 1934번: 최소공배수 (0) | 2023.08.23 |
| [BAEKJOON] 10430번: 나머지 (0) | 2023.08.23 |
| [BAEKJOON] 9012번: 괄호 (0) | 2023.08.22 |
| [BAEKJOON] 10866번: 덱 (0) | 2023.08.22 |