Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 오에스
- 브루트포스
- 구현
- 그래프
- 정석
- 컴공과
- 컴공
- c++
- DP
- 너비우선탐색
- 자료구조
- 컴퓨터공학과
- coding
- Operating System
- Computer science
- 개발
- 북리뷰
- OS
- 알고리즘
- bfs
- Stack
- 코딩
- 백준
- 오퍼레이팅시스템
- 정석학술정보관
- 문제풀이
- 코테
- cs
- vector
- 스택
Archives
- Today
- Total
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