백준
백준 소스코드 [C++] 1934 최소공배수
Hani_Levenshtein
2020. 9. 9. 15:21
1934번: 최소공배수
두 자연수 A와 B에 대해서, A의 배수이면서 B의 배수인 자연수를 A와 B의 공배수라고 한다. 이런 공배수 중에서 가장 작은 수를 최소공배수라고 한다. 예를 들어, 6과 15의 공배수는 30, 60, 90등이 있�
www.acmicpc.net
백준 소스코드 [C++] 1934 최소공배수
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
int gcd(int a, int b) {
if (a > b) swap(a, b);
if (b % a == 0) return a;
else return gcd(a, b % a);
}
int lcm(int a,int b) {
return a * b / gcd(a, b);
}
int main() {
int n;
int a, b;
cin >> n;
while (n--) {
cin >> a >> b;
cout << lcm(a, b)<<'\n';
}
return 0;
}