Algorithm/BOJ
[백준/1934] 최소공배수 (with 파이썬)
Potato potage
2022. 12. 17. 20:19
반응형
✔ 문제
✔ 풀이
👾 유클리드 호제법
import sys
input = sys.stdin.readline
def gcd(x, y):
while y > 0:
x, y = y, x % y
return x
def lcm(x, y):
return x * y // gcd(x, y)
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
print(lcm(a, b))
👻 math 라이브러리 사용
import math
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
print(math.lcm(a, b))
반응형