Skip to content
Prev Previous commit
Next Next commit
Update 약수의 개수와 덧셈.js
  • Loading branch information
jaewon1676 committed Apr 4, 2022
commit bbe66be3e11ac4223d09ddcd8795c7b73058d454
18 changes: 17 additions & 1 deletion level-1/약수의-개수와-덧셈.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ const divisorCounter = (num) => {
const sqrt = Math.sqrt(num)
for (let i = 1; i <= sqrt; i++) if (num % i === 0) count += 1
return Number.isInteger(sqrt) ? (count - 1) * 2 + 1 : count * 2
}
}

//정답 3 - jaewon1676
function solution(left, right) {
var answer = 0;

for (left; left<=right; left++){
// left의 제곱근이 정수면 약수의 개수는 홀수
if (Number.isInteger(Math.sqrt(left))){
answer -= left
} else {
answer += left
}
}
return answer;
}
//