Sub topic 5
Counting the Factors of a Number
Assume you know integer arithmetic, exponent notation, and basic prime factorization. This chapter develops a formula for counting positive factors quickly, without listing every factor.
The factor-count formula
A factor of a positive integer \(n\) is a positive integer that divides \(n\) exactly. Write the prime factorization of \(n\) as
\[ n=p1^{e1}p2^{e2}\cdots pk^{ek}, \]
where the \(pi\) are distinct primes and the \(ei\) are their exponents.
Every factor of \(n\) must choose:
- an exponent from \(0\) to \(e1\) for \(p1\),
- an exponent from \(0\) to \(e2\) for \(p2\),
- and so on.
Therefore, the number of positive factors is
\[ \tau(n)=(e1+1)(e2+1)\cdots(e_k+1). \]
The symbol \(\tau(n)\) means the number of positive factors of \(n\).
For example,
\[ 360=2^3\cdot3^2\cdot5^1. \]
The exponent choices are \(0,1,2,3\) for 2, \(0,1,2\) for 3, and \(0,1\) for 5. Thus,
\[ \tau(360)=(3+1)(2+1)(1+1)=24. \]
| Number | Prime factorization | Number of positive factors |
|---|---|---|
| 360 | \(2^3\cdot3^2\cdot5\) | \(4\cdot3\cdot2=24\) |
A worked computational example
def factorize(n):
factors = {}
p = 2
while p * p <= n:
while n % p == 0:
factors[p] = factors.get(p, 0) + 1
n //= p
p += 1
if n > 1:
factors[n] = factors.get(n, 0) + 1
return factors
n = 360
factorization = factorize(n)
count = 1
for exponent in factorization.values():
count *= exponent + 1
print(factorization) # {2: 3, 3: 2, 5: 1}
print(count) # 24The algorithm first finds the prime exponents. It then multiplies one more than each exponent.
Common errors
Counting distinct prime factors
The number \(360\) has three distinct prime factors: 2, 3, and 5. However, it has 24 positive factors. Do not confuse the number of distinct primes with the total number of factors.
Forgetting exponent zero
A factor may contain no copy of a particular prime. For example, \(3^0=1\). This is why an exponent \(e\) gives \(e+1\) choices, not \(e\) choices.
Using the formula before factorizing
The formula applies to the exponents in the prime factorization. For \(72=2^3\cdot3^2\),
\[ \tau(72)=(3+1)(2+1)=12. \]
Using 72 and 3 directly in the formula has no meaning.
Why perfect squares are special
Factors usually form pairs:
\[ d\cdot\frac{n}{d}=n. \]
For a non-square, the two factors in each pair are different, so the factor count is even. For a perfect square, one pair meets at \(\sqrt n\), so the count is odd.
This gives a useful check:
- If \(n\) is not a square, \(\tau(n)\) must be even.
- If \(n\) is a square, \(\tau(n)\) must be odd.
Exercise
How many positive factors does 2^4 × 3^2 × 7 have? Is the number represented by this expression a perfect square?
Show answer
The factor count is (4 + 1)(2 + 1)(1 + 1) = 30. The number is not a perfect square because the exponents 4, 2, and 1 are not all even.