백준 풀이 C++
백준 2702 C++(유클리드 호제법)
ag2개발자
2022. 9. 22. 19:38
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss stable_sort
#define ll long long
int gcd(int x, int y) {
int r;
while (y!=0) {
r = x % y;
x = y;
y = r;
}
return x;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
// for(int i=0; i< n;i++)
int t;
cin >> t;
int x, y;
while(t--){
cin >> x >> y;
cout << (x * y) / gcd(x, y) << " ";
cout << gcd(x,y) << "\n";
}
return 0;
}