728x90
π μ½μμ κ°μ
=> μ κ³±κ·Όμ΄ μ μλ©΄, μ½μμ κ°μλ νμλ€!!
Number.isInteger(Math.sqrt(i))
function solution(left, right) {
var answer = 0;
for (let i = left; i <= right; i++) {
if (Number.isInteger(Math.sqrt(i))) {
answer -= i;
} else {
answer += i;
}
}
return answer;
}
Number μ isInteger. ν¨μλ‘ i μ μ κ³±κ·Όμ΄ μ μμΈμ§ νλ³ν΄μ£Όλ λ°©μ
λ¬Όλ‘ λλ μ΄κ±Έ λͺ°λμ΄μ
function solution(left, right) {
const countingMeasure = (num) => {
const measure = [];
for (let j = 1; j <= num; j++) {
if (num % j === 0) measure.push(j)
}
return measure.length;
}
let result = 0;
for (let i = left; i <= right; i++) {
if (countingMeasure(i) % 2 == 0) result += i;
if (countingMeasure(i) % 2 != 0) result -= i;
}
return result;
}
μ΄λ κ² μ½μμ κ°μλ₯Ό μ§μ μΈμ νμλ€~~
728x90
λ°μν