Kata
Count the number of divisors of a positive integer n.
Random tests go up to n = 500000.
Examples1
2
3
4divisors(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
# My Solutions
1 | function getDivisorsCnt(n){ |
# Others
for문
1 | function getDivisorsCnt(n) { |
# thoughts
- 원하는 값은 갯수. 굳이 배열의 길이로 구현하지 않아도 된다.
- !n%i 로 계산하면 제대로 된 연산이 되지 않는다. !(n%i) 감싸줄 것.