Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 2702번 - 초6 수학 본문
간단한 gcd, lcm 문제
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
cout << lcm(x, y) << " " << gcd(x, y) << "\n";
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 13241번 - 최소공배수 (0) | 2021.08.21 |
|---|---|
| [C++] 백준 11508번 - 2 + 1 세일 (0) | 2021.08.21 |
| [C++] 백준 1912번 - 연속합 (0) | 2021.08.21 |
| [C++] 백준 1850번 - 최대공약수 (0) | 2021.08.21 |
| [C++] 백준 5430번 틀 (0) | 2021.08.20 |
Comments