Counting Divisors From a Prime Factorisation
A standard interview trick — once a number is broken into its prime factors, the count of its divisors falls out of a single formula, no listing required.
"How many divisors does 360 have?" is a common interview warm-up, and listing them by hand is slow and error-prone once the number gets past a couple dozen. The clean approach is to first write the number as a product of prime powers, then use a formula that converts that factorisation directly into a divisor count.
If a number factors as , where each is a distinct prime, then the number of positive divisors of is . The reasoning is that any divisor of is built by picking, independently for each prime, one of possible exponents (0 through ), and multiplying the choices together — the count of divisors is just the count of these independent choices multiplied out.
For : factorise it as . The exponents are 3, 2, and 1, so the divisor count is . Indeed, 360 has exactly 24 positive divisors — a fact that would take real patience to verify by listing them one at a time.
The same trick extends naturally: interviewers sometimes ask for the number of divisors that are themselves perfect squares, or the sum of all divisors (a related but different formula, ), so recognising that the whole family of divisor questions reduces to "factorise first" is the transferable skill, not memorising one specific formula.
Once a number is written as a product of prime powers , its total number of divisors is simply — turning a tedious listing exercise into one multiplication.
Practice in interviews
Further reading
- Standard quant interview puzzle collections