Practice · 2 of 6
Count the Divisors
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Given a positive integer n, print how many divisors it has.
**Input:** One integer n (1 ≤ n ≤ 10^12).
**Output:** One integer — the divisor count.
**Example:** 12 → 6 (1, 2, 3, 4, 6, 12).
*Careful:* looping i from 1 to n is far too slow for 10^12. Loop i while
i * i <= n and count each divisor pair (i, n/i) — remember i = n/i when
n is a perfect square.
Press Submit to check your solution.
Back to lesson: Practice: Loop Patterns Set