Code RoomCount divisors
MediumPrep Room Coding #743

Count divisors

CodingAlgorithms & data structuresMid–Senior~18 min

Given a positive integer n (1 <= n <= 10^12), return the number of positive divisors of n, including 1 and n itself. For example, 12 has divisors 1, 2, 3, 4, 6, 12, so the answer is 6. The value of n can be large enough that listing every candidate up to n is too slow.

Implement
count_divisors(n: int) → int
Examples
in[12]out6
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 18 min
InputExpectedGot
[12]6not run yetsample