Number TheoryPrimes and Factorization

Counting and Adding Divisors

If n = p₁^a₁ ⋯ pₖ^aₖ, then n has (a₁ + 1)⋯(aₖ + 1) divisors, and their sum σ(n) is a product of geometric sums.

Not started Jump to practice

How many divisors does $360$ have, and what do they add up to? Listing them works but is slow and easy to get wrong. With the prime factorization in hand, both questions have formulas.

Notation. $\tau(n)$ is the number of positive divisors of $n$ (also written $d(n)$), and $\sigma(n)$ is their sum. For $n = 12$: the divisors are $1, 2, 3, 4, 6, 12$, so $\tau(12) = 6$ and $\sigma(12) = 28$.

Formulas. If $n = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}$, then $$\tau(n) = (a_1 + 1)(a_2 + 1) \cdots (a_k + 1), \qquad \sigma(n) = \prod_{i=1}^{k} \left(1 + p_i + p_i^{2} + \cdots + p_i^{a_i}\right) = \prod_{i=1}^{k} \frac{p_i^{a_i + 1} - 1}{p_i - 1}.$$

Why it works

By unique factorization, the divisors of $n$ are exactly the numbers $p_1^{e_1} \cdots p_k^{e_k}$ with $0 \le e_i \le a_i$, each exponent chosen independently. Exponent $e_i$ has $a_i + 1$ choices (counting $0$), and choices multiply. For $\sigma$, expand the product of the brackets: each term of the expansion picks one power of each prime, so each divisor appears exactly once. Each bracket is a finite geometric series.
The divisors of $72 = 2^{3} \cdot 3^{2}$: one for each choice of a row and a column, $4 \cdot 3 = 12$ in all.
$3^{0} = 1$$3^{1} = 3$$3^{2} = 9$
$2^{0} = 1$139
$2^{1} = 2$2618
$2^{2} = 4$41236
$2^{3} = 8$82472

Worked example: Counting divisors

Find $\tau(360)$.
  1. $360 = 2^{3} \cdot 3^{2} \cdot 5$.
  2. $\tau(360) = (3 + 1)(2 + 1)(1 + 1) = 4 \cdot 3 \cdot 2 = 24$.

Answer: $24$.

Worked example: Adding divisors

Find $\sigma(72)$.
  1. $72 = 2^{3} \cdot 3^{2}$.
  2. $\sigma(72) = (1 + 2 + 4 + 8)(1 + 3 + 9) = 15 \cdot 13 = 195$.
  3. Check by adding the table's twelve entries: $1 + 2 + 3 + 4 + 6 + 8 + 9 + 12 + 18 + 24 + 36 + 72 = 195$.

Answer: $195$.

Worked example: Designing a number

What is the smallest positive integer with exactly $12$ divisors?
  1. We need $(a_1 + 1)(a_2 + 1) \cdots = 12$. The ways to write $12$: $12$, $6 \cdot 2$, $4 \cdot 3$, $3 \cdot 2 \cdot 2$.
  2. Give the biggest exponent to the smallest prime: $2^{11} = 2048$, $\ 2^{5} \cdot 3 = 96$, $\ 2^{3} \cdot 3^{2} = 72$, $\ 2^{2} \cdot 3 \cdot 5 = 60$.
  3. The smallest is $60$.

Answer: $60$.

Common mistake

Multiplying the exponents instead of the exponents plus one: "$\tau(72) = 3 \cdot 2 = 6$." That forgets that each prime may also appear to the power $0$ (the first row and column of the table). The correct count is $(3 + 1)(2 + 1) = 12$.

A pleasant consequence: $\tau(n)$ is odd exactly when $n$ is a perfect square. Divisors come in pairs $d$ and $n/d$, like $2$ and $36$ for $72$, and a pair collapses to a single divisor only when $d = n/d$, that is, $d^{2} = n$. In the formula, $\tau(n)$ is odd exactly when every $a_i + 1$ is odd, so every exponent $a_i$ is even.

Both functions are multiplicative: if $\gcd(m, n) = 1$, then $\tau(mn) = \tau(m)\tau(n)$ and $\sigma(mn) = \sigma(m)\sigma(n)$. That is exactly why the formulas are products over the primes.

Key idea

From $n = \prod p^{a}$: the number of divisors is $\prod (a + 1)$, and their sum is $\prod (1 + p + \cdots + p^{a})$.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • William Stein, Elementary Number Theory: Primes, Congruences, and Secrets (Springer, 2009; free online edition), chapter 1, Prime Numbers
  • MIT OpenCourseWare 18.781 Theory of Numbers (Spring 2012), lecture notes on arithmetic functions
@teddyrookbook GitHub