카펫
노란색 카펫 수의 약수 a와 b를 구해서 a와 b가 2a+2b+4인 조건을 만족하는 a, b를 찾는 문제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function solution(brown, yellow) {
var answer = [];
if (yellow === 1 || yellow === 0) {
answer.push(yellow + 2);
answer.push(yellow + 2);
} else {
for (let i = 1; i <= yellow/2; i++) {
if (yellow % i === 0) {
const j = yellow / i;
const value = 2 * i + 2 * j + 4;
if (value === brown) {
answer.push(j + 2);
answer.push(i + 2);
break;
}
}
}
}
return answer;
}