-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs12940.js
More file actions
27 lines (25 loc) · 818 Bytes
/
Copy pathjs12940.js
File metadata and controls
27 lines (25 loc) · 818 Bytes
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
const solution = (n, m) => {
// n, m 중에서 작은수가 큰수를 나누었을때 0이면 작은 수는 최소 공약수 / 큰수는 최소 공배수
let [divisor, multiple] =
(n>=m&&n%m==0&&[m,n])||
(n<=m&&m%n==0&&[n,m])||
[false,false];
// 초기값이 비었을 경우 계산
if(!divisor){
// 작은 수의 루트부터 차감하면서 최대 공약수 계산
let point = Math.floor((n>=m&&m||n)/2);
while(point>1){
if(n%point==0&&m%point==0){
break;
}
--point;
}
divisor = point
multiple = (n*m)/point
}
return [divisor, multiple];
}
// console.log(solution(3,12))
// console.log(solution(1,1))
// console.log(solution(8,10))
console.log(solution(12,18))