18 - Count the divisors of a number
Q.
Count the number of divisors of a positive integer n.
Random tests go up to n = 500000.
Examples
divisors(4) = 3 // 1, 2, 4
divisors(5) = 2 // 1, 5
divisors(12) = 6 // 1, 2, 3, 4, 6, 12
divisors(30) = 8 // 1, 2, 3, 5, 6, 10, 15, 30
A)
function getDivisorsCnt(n){
// todo
let count = 0;
if(n===1){
return 1
}
for (i=1 ; i<=n ; i++) {
if(n%i === 0) {
count++
}
}
return count
}
Author And Source
이 문제에 관하여(18 - Count the divisors of a number), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@developerjhp/알고리즘-18-
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
function getDivisorsCnt(n){
// todo
let count = 0;
if(n===1){
return 1
}
for (i=1 ; i<=n ; i++) {
if(n%i === 0) {
count++
}
}
return count
}
Author And Source
이 문제에 관하여(18 - Count the divisors of a number), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@developerjhp/알고리즘-18-저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)