Number of Divisors and Sum of Divisors

From the prime factorization n = p^e × q^f …, finds the number of divisors as (e+1)(f+1)… and their sum as (1 + p + … + p^e)(1 + q + … + q^f)….

You do not have to hunt for divisors one at a time. Once the prime factorization is known, both the number of divisors and their total come out of a simple product. Suppose n=pe×qf×n = p^e \times q^f \times \cdots.

The number of divisors d(n)d(n) is found by adding 1 to each exponent and multiplying.

d(n)=(e+1)(f+1)d(n) = (e+1)(f+1)\cdots

The sum of the divisors σ(n)\sigma(n) multiplies together, for each prime, the total of its powers from 1 up to pep^e.

σ(n)=(1+p++pe)(1+q++qf)\sigma(n) = (1 + p + \cdots + p^e)(1 + q + \cdots + q^f)\cdots

The count formula makes sense once you picture how a divisor gets built: choose how many copies of pp to take, anywhere from 0 to ee, then do the same for qq, and so on. That is e+1e + 1 choices for pp, and every combination of choices lands on a different divisor.

Example

Take n=36n = 36. Since 36=22×3236 = 2^2 \times 3^2:

d(36)=(2+1)(2+1)=9d(36) = (2+1)(2+1) = 9
σ(36)=(1+2+4)(1+3+9)=7×13=91\sigma(36) = (1 + 2 + 4)(1 + 3 + 9) = 7 \times 13 = 91

And indeed the divisors of 36 are 1, 2, 3, 4, 6, 9, 12, 18 and 36. Nine of them, adding to 91.

Notes