Editor

Count the Divisors

#280 · Math · Intermediate · 65 XP · about 10 min

A school hall has n chairs to set out in a rectangle: every row holds the same number of chairs and none are left over. 12 chairs can make 1 row of 12, 2 rows of 6, 3 of 4, 4 of 3, 6 of 2 or 12 of 1: six layouts, one for each divisor of 12.

Write count_divisors(n) that returns how many positive divisors n has.

Examples

count_divisors(12)    # returns 6
count_divisors(36)    # returns 9
count_divisors(97)    # returns 2
count_divisors(1)     # returns 1

Constraints

  • 1 <= n <= 10^12, so checking every number from 1 to n takes far too long.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.