File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
백준/Bronze/2609. 최대공약수와 최소공배수 Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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 ) ) ;
You can’t perform that action at this time.
0 commit comments