문제 링크: https://www.acmicpc.net/problem/1934
백준 정수론 및 조합론 4단계 - 1934번 최소공배수를 풀어보았다.
풀이: 최소공배수는 두 수의 곱을 최대공약수로 나누면 된다.
C++
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int a,b;
cin>>a>>b;
cout<<lcm(a,b)<<"\n";
}
}
Python
import math
n=int(input())
for i in range(n):
a,b=map(int,input().split())
gcds=math.gcd(a,b)
print(int(a*b/gcds))
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
이항 계수 2 풀이 (0) | 2023.01.09 |
---|---|
이항 계수 1 풀이 (0) | 2023.01.09 |
링 풀이 (0) | 2023.01.09 |
검문 풀이 (0) | 2023.01.09 |
최대공약수와 최소공배수 풀이 (0) | 2023.01.09 |