Academy
MathsNumber TheoryDivisibilityCounting and Summing Divisors

Counting and Summing Divisors

How many divisors does n have? What is their sum? The answers come from the prime factorization of n, and the formulas are cleaner than you'd expect.

How many divisors does 360 have?

You could list them. That works for 360. It fails when the number is large, or when the problem asks you to count divisors of n10n^{10} without knowing nn.

There's a formula. It comes entirely from prime factorization, and understanding why it works is more useful than the formula itself.


The number of divisors — τ(n)\tau(n)

Theorem. If n=p1a1p2a2pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}, then the number of positive divisors of nn is:

τ(n)=(a1+1)(a2+1)(ak+1)\tau(n) = (a_1 + 1)(a_2 + 1) \cdots (a_k + 1)

Why. Every divisor of nn has the form d=p1e1p2e2pkekd = p_1^{e_1} p_2^{e_2} \cdots p_k^{e_k} where 0eiai0 \leq e_i \leq a_i.

For each prime pip_i, there are ai+1a_i + 1 choices for eie_i (from 0 to aia_i). The choices are independent, so multiply.

Example. 360=23×32×51360 = 2^3 \times 3^2 \times 5^1.

τ(360)=(3+1)(2+1)(1+1)=4×3×2=24\tau(360) = (3+1)(2+1)(1+1) = 4 \times 3 \times 2 = 24.

360 has 24 positive divisors.

Example. τ(pk)=k+1\tau(p^k) = k+1 for any prime pp. The divisors are 1,p,p2,,pk1, p, p^2, \ldots, p^k.

Example. τ(p)=2\tau(p) = 2 for any prime pp. Exactly two divisors: 1 and pp. This is the definition of a prime.


Perfect squares and odd τ\tau

Theorem. nn is a perfect square     \iff τ(n)\tau(n) is odd.

Proof. Divisors pair up: if dnd \mid n, then n/dnn/d \mid n, and dn/dd \neq n/d unless d=nd = \sqrt{n}.

So divisors come in pairs except when d=n/dd = n/d, i.e., d2=nd^2 = n. The count is odd iff nn is a perfect square. \blacksquare

Using the formula: τ(n)=(ai+1)\tau(n) = \prod(a_i+1) is odd     \iff each ai+1a_i+1 is odd     \iff each aia_i is even     \iff nn is a perfect square.


The sum of divisors — σ(n)\sigma(n)

Theorem. If n=p1a1p2a2pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}, then the sum of all positive divisors of nn is:

σ(n)=i=1kpiai+11pi1=i=1k(1+pi+pi2++piai)\sigma(n) = \prod_{i=1}^{k} \frac{p_i^{a_i+1} - 1}{p_i - 1} = \prod_{i=1}^{k} (1 + p_i + p_i^2 + \cdots + p_i^{a_i})

Why. When you expand the product:

(1+p1++p1a1)(1+p2++p2a2)(1+pk++pkak)(1 + p_1 + \cdots + p_1^{a_1})(1 + p_2 + \cdots + p_2^{a_2}) \cdots (1 + p_k + \cdots + p_k^{a_k})

each term in the expansion is p1e1p2e2pkekp_1^{e_1} p_2^{e_2} \cdots p_k^{e_k} with 0eiai0 \leq e_i \leq a_i — exactly the divisors of nn. Summing all terms gives σ(n)\sigma(n). \blacksquare

Example. σ(360)\sigma(360) where 360=23×32×5360 = 2^3 \times 3^2 \times 5.

σ(360)=(1+2+4+8)(1+3+9)(1+5)=15×13×6=1170\sigma(360) = (1+2+4+8)(1+3+9)(1+5) = 15 \times 13 \times 6 = 1170


Multiplicativity

Both τ\tau and σ\sigma are multiplicative: if gcd(m,n)=1\gcd(m, n) = 1, then:

τ(mn)=τ(m)τ(n)σ(mn)=σ(m)σ(n)\tau(mn) = \tau(m)\,\tau(n) \qquad \sigma(mn) = \sigma(m)\,\sigma(n)

Why. The prime factorizations of mm and nn share no primes (since gcd(m,n)=1\gcd(m,n)=1). So the product formula for τ(mn)\tau(mn) splits cleanly into the product for τ(m)\tau(m) times the product for τ(n)\tau(n).

This multiplicativity is why the formulas factor over primes — each prime contributes independently.

Common mistake. τ(mn)=τ(m)τ(n)\tau(mn) = \tau(m)\tau(n) requires gcd(m,n)=1\gcd(m,n) = 1. Without it: τ(4)=3\tau(4) = 3 but τ(2)τ(2)=4\tau(2)\tau(2) = 4. They differ.


Perfect numbers

A positive integer nn is perfect if σ(n)=2n\sigma(n) = 2n — it equals the sum of all its proper divisors (divisors excluding itself).

Examples: 6=1+2+36 = 1+2+3 and 28=1+2+4+7+1428 = 1+2+4+7+14. Both perfect.

Euler's theorem on even perfect numbers. nn is an even perfect number     \iff n=2p1(2p1)n = 2^{p-1}(2^p - 1) where 2p12^p - 1 is prime (a Mersenne prime).

Proof sketch. Write n=2kmn = 2^{k} m with mm odd. Then σ(n)=σ(2k)σ(m)=(2k+11)σ(m)\sigma(n) = \sigma(2^k)\sigma(m) = (2^{k+1}-1)\sigma(m). Setting σ(n)=2n=2k+1m\sigma(n) = 2n = 2^{k+1}m and solving forces m=2k+11m = 2^{k+1}-1 (a prime) and k=p1k = p-1.

Whether any odd perfect numbers exist is an open problem.


Worked problems

Problem 1. Find the number of divisors of 101010^{10}.

1010=210×51010^{10} = 2^{10} \times 5^{10}.

τ(1010)=(10+1)(10+1)=121\tau(10^{10}) = (10+1)(10+1) = 121.

Problem 2. For how many values of n100n \leq 100 is τ(n)\tau(n) odd?

τ(n)\tau(n) is odd     \iff nn is a perfect square. Perfect squares 100\leq 100: 1,4,9,,1001, 4, 9, \ldots, 100. That is 10 values.

Problem 3. Find all nn such that τ(n)=2\tau(n) = 2.

τ(n)=2    n\tau(n) = 2 \iff n has exactly 2 divisors     \iff nn is prime. \blacksquare

Problem 4. Find σ(2k)\sigma(2^k) and verify it equals 2k+112^{k+1} - 1.

σ(2k)=1+2+4++2k=2k+11\sigma(2^k) = 1 + 2 + 4 + \cdots + 2^k = 2^{k+1} - 1. (Geometric series.) ✓

Note: σ(2k)\sigma(2^k) is always odd. So 2k2^k is never perfect — a perfect number requires σ(n)=2n\sigma(n) = 2n which is even.

Problem 5. If n=paqbn = p^a q^b with p,qp, q distinct primes, find τ(n2)\tau(n^2) in terms of τ(n)\tau(n).

n2=p2aq2bn^2 = p^{2a}q^{2b}.

τ(n2)=(2a+1)(2b+1)\tau(n^2) = (2a+1)(2b+1).

τ(n)=(a+1)(b+1)\tau(n) = (a+1)(b+1).

No clean relationship in general. But if a=ba = b: τ(n)=(a+1)2\tau(n) = (a+1)^2 and τ(n2)=(2a+1)2\tau(n^2) = (2a+1)^2.

Problem 6. Find the sum of all divisors of 496. Is 496 perfect?

496=16×31=24×31496 = 16 \times 31 = 2^4 \times 31.

σ(496)=(1+2+4+8+16)(1+31)=31×32=992=2×496\sigma(496) = (1+2+4+8+16)(1+31) = 31 \times 32 = 992 = 2 \times 496.

Yes, 496 is perfect. (And 31=25131 = 2^5 - 1 is a Mersenne prime, confirming Euler's theorem.)

Problem 7. How many ordered pairs (a,b)(a, b) of positive integers satisfy lcm(a,b)=n\text{lcm}(a, b) = n?

For n=p1e1pkekn = p_1^{e_1} \cdots p_k^{e_k}: each prime pip_i contributes independently. If aa has piαip_i^{\alpha_i} and bb has piβip_i^{\beta_i}, then max(αi,βi)=ei\max(\alpha_i, \beta_i) = e_i.

Pairs (αi,βi)(\alpha_i, \beta_i) with max=ei\max = e_i: total pairs with both ei\leq e_i is (ei+1)2(e_i+1)^2; subtract pairs where both ei1\leq e_i - 1, giving (ei+1)2ei2=2ei+1(e_i+1)^2 - e_i^2 = 2e_i + 1.

Total ordered pairs: i=1k(2ei+1)=τ(n2)\prod_{i=1}^k (2e_i + 1) = \tau(n^2).


The pattern connecting everything

τ(n)=dn1σ(n)=dndσk(n)=dndk\tau(n) = \sum_{d \mid n} 1 \qquad \sigma(n) = \sum_{d \mid n} d \qquad \sigma_k(n) = \sum_{d \mid n} d^k

These are all special cases of Dirichlet series — sums over divisors. The deeper theory of how they multiply and interact is the Dirichlet convolution, which lives in Dirichlet's Divisor Problem.