[백준/Python3] 1934 최소공배수

nyam·2022년 3월 10일
0

백준

목록 보기
11/34
post-thumbnail

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


풀이

두 수 a, b가 있을 때, a와 b의 최소공배수는 a * b / GCD(a, b)로 구할 수 있다. 여기서 최대공약수 GCD는 유클리드 호제법을 통해 간단히 구할 수 있다.

코드

import sys

def get_gcd(a: int, b: int) -> int:
    if a < b:
        return get_gcd(b, a)
    if b == 0:
        return a
    else:
        return get_gcd(b, a%b)

def solution(a: int, b: int):
    return print(int(a * b / get_gcd(a, b)))

for _ in range(int(input())):
    a, b = map(int, sys.stdin.readline().split())
    solution(a, b)

0개의 댓글