Skip to the code
cf.
+25 XP

#647 Count the Divisors

medium

A grid layout tool offers every column count that divides the number of items evenly. To size the dropdown, it needs to know how many such counts exist.

Write countDivisors(n) that returns how many whole numbers from 1 to n divide n with no remainder.

Example 1

Input: n = 12
Output: 6

1, 2, 3, 4, 6, and 12 divide 12.

Example 2

Input: n = 1
Output: 1

Only 1 divides 1.

Constraints

  • 1 <= n <= 10^12
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).