백준
백준 소스코드 [C++] 5347 LCM
Hani_Levenshtein
2020. 8. 27. 19:27
https://www.acmicpc.net/problem/5347
5347번: LCM
첫째 줄에 테스트 케이스의 개수 n이 주어진다. 다음 n개 줄에는 a와 b가 주어진다. a와 b사이에는 공백이 하나 이상 있다. 두 수는 백만보다 작거나 같은 자연수이다.
www.acmicpc.net
백준 소스코드 [C++] 5347 LCM
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <string>
using namespace std;
int gcd(int n, int m) {
return n % m ? gcd(m, n % m) : m;
}
int lcm(int n, int m) {
return n / gcd(n, m)*m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, t;
cin >> t;
while (t--) {
cin >> n >> m;
cout << lcm(n, m) << '\n';
}
return 0;
}