Skip to content

Commit e5a7da4

Browse files
committed
Merge branch 'main' of https://github.com/ho0010/algorithm
2 parents d8adfc4 + 6bad913 commit e5a7da4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Bronze I] 최대공약수와 최소공배수 - 2609
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2609)
4+
5+
### 성능 요약
6+
7+
메모리: 9596 KB, 시간: 104 ms
8+
9+
### 분류
10+
11+
유클리드 호제법, 수학, 정수론
12+
13+
### 제출 일자
14+
15+
2025년 3월 5일 22:52:40
16+
17+
### 문제 설명
18+
19+
<p>두 개의 자연수를 입력받아 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에는 두 개의 자연수가 주어진다. 이 둘은 10,000이하의 자연수이며 사이에 한 칸의 공백이 주어진다.</p>
24+
25+
### 출력
26+
27+
<p>첫째 줄에는 입력으로 주어진 두 수의 최대공약수를, 둘째 줄에는 입력으로 주어진 두 수의 최소 공배수를 출력한다.</p>
28+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let fs = require('fs');
2+
let input = fs.readFileSync('/dev/stdin').toString().trim().split(' ');
3+
4+
let [a, b] = input.map(Number);
5+
6+
const gcd = (x, y) => {
7+
while (y !== 0) {
8+
[x, y] = [y, x % y];
9+
}
10+
return x;
11+
};
12+
13+
const lcm = (x, y) => (x * y) / gcd(x, y);
14+
15+
console.log(gcd(a, b));
16+
console.log(lcm(a, b));

0 commit comments

Comments
 (0)