All problems
Divisors Count
Problem
Return the number of positive divisors of n.
Loop i up to the square root and count each divisor, adding two for its partner unless i is exactly the square root. Assume n >= 1.
Hint
Divisors pair up as i and n // i, except for a perfect square root.
Test cases
case 1
in: [1]
expected: 1
case 2
in: [12]
expected: 6
case 3
in: [36]
expected: 9
case 4
in: [97]
expected: 2
case 5
in: [1000]
expected: 16
Starter codePython
def divisor_count(n):
# Your code here
pass5 test cases · run your code against them in the editor