Sub topic 6
Sum of Factors
This chapter assumes you can write a number as a product of prime powers, and that you can count its factors with the (e + 1) rule from the previous chapter. It also assumes you are comfortable with exponents and with summing a geometric series. Here you will learn to find the sum of all factors of a number directly from its prime factorization, and how to adapt that sum to the variants CAT asks about.
Why a formula is needed
Take 360. Listing its 24 factors and adding them is slow and easy to get wrong. The prime factorization 360 = 2^3 x 3^2 x 5 gives the same total in three short steps.
The idea is that every factor of 360 is built by picking a power of 2 (from 2^0 to 2^3), a power of 3 (from 3^0 to 3^2) and a power of 5 (from 5^0 to 5^1). Multiplying out the sum
(1 + 2 + 4 + 8) x (1 + 3 + 9) x (1 + 5)
produces every such combination exactly once. So the product of these brackets is the sum of all factors.
The formula
If n = p1^e1 x p2^e2 x ... x pk^ek, where the p values are distinct primes, then
sigma(n) = product over each prime of (1 + p + p^2 + ... + p^e) = product of (p^(e+1) - 1) / (p - 1)
Each bracket is a geometric series with first term 1 and ratio p. That is where the closed form (p^(e+1) - 1) / (p - 1) comes from.
For 360:
- Prime 2, exponent 3: (2^4 - 1) / (2 - 1) = 15
- Prime 3, exponent 2: (3^3 - 1) / (3 - 1) = 13
- Prime 5, exponent 1: (5^2 - 1) / (5 - 1) = 6
The sum is 15 x 13 x 6 = 1170.
Checking the formula in code
The program below factorizes a number, then computes both the factor count and the factor sum. It also brute-forces the sum so you can confirm the formula.
def factorize(n):
f = {}
p = 2
while p * p <= n:
while n % p == 0:
f[p] = f.get(p, 0) + 1
n //= p
p += 1
if n > 1:
f[n] = f.get(n, 0) + 1
return f
def sigma(n):
total = 1
for p, e in factorize(n).items():
total *= (p ** (e + 1) - 1) // (p - 1)
return total
def sigma_brute(n):
return sum(d for d in range(1, n + 1) if n % d == 0)
for n in (360, 100, 97, 1000):
print(n, factorize(n), sigma(n), sigma_brute(n))For 360 both methods give 1170. For the prime 97 the sum is 1 + 97 = 98, which matches the formula with a single bracket (97^2 - 1) / 96 = 98.
Worked examples
Example 1: Sum of all factors
Find the sum of the factors of 720.
- 720 = 2^4 x 3^2 x 5.
- Bracket for 2: 1 + 2 + 4 + 8 + 16 = 31.
- Bracket for 3: 1 + 3 + 9 = 13.
- Bracket for 5: 1 + 5 = 6.
- Sum = 31 x 13 x 6 = 2418.
Example 2: Sum of proper factors
Proper factors usually means all factors except the number itself. So the sum is sigma(n) - n. For 720 this is 2418 - 720 = 1698.
Some questions use "proper" to also exclude 1. Read the wording and subtract 1 as well if it says so.
Example 3: Sum of odd factors
Find the sum of the odd factors of 360.
An odd factor uses no power of 2. So ignore the bracket for 2 and multiply only the brackets for the odd primes:
(1 + 3 + 9) x (1 + 5) = 13 x 6 = 78.
Example 4: Sum of even factors
The even factors are all factors except the odd ones. So the sum of even factors of 360 is 1170 - 78 = 1092.
You can also get this directly. An even factor must contain at least one 2. Replace the bracket for 2 with (2 + 4 + 8) = 14. Then 14 x 13 x 6 = 1092, which agrees.
Example 5: Sum of factors that are multiples of a given number
Find the sum of the factors of 360 that are divisible by 6 = 2 x 3.
Each such factor needs at least one 2 and at least one 3. Start both brackets at the first power:
- Power of 2: 2 + 4 + 8 = 14
- Power of 3: 3 + 9 = 12
- Power of 5: 1 + 5 = 6
The sum is 14 x 12 x 6 = 1008.
Example 6: Sum of factors that are perfect squares
A square factor has even exponents only. For 360 = 2^3 x 3^2 x 5:
- Power of 2: 2^0 and 2^2 give 1 + 4 = 5
- Power of 3: 3^0 and 3^2 give 1 + 9 = 10
- Power of 5: only 5^0 is allowed, giving 1
The sum is 5 x 10 x 1 = 50. The square factors are 1, 4, 9 and 36, plus 4 x 9 = 36 already counted, and so the full list is 1, 4, 9, 36. Wait: 1 + 4 + 9 + 36 = 50, which matches.
How the choices combine
Useful results built on the formula
| Question type | What to do | Result for 360 |
|---|---|---|
| Sum of all factors | Multiply all full brackets | 1170 |
| Sum of odd factors | Drop the bracket for 2 | 78 |
| Sum of even factors | All minus odd | 1092 |
| Sum of proper factors | All minus n | 810 |
| Sum of factors divisible by d | Start each bracket at the exponent in d | depends on d |
| Sum of square factors | Keep only even exponents | 50 |
Perfect numbers and a quick sanity check
A number is perfect when its proper factors sum to the number itself, so sigma(n) = 2n. For 28 = 2^2 x 7, sigma = 7 x 8 = 56 = 2 x 28. So 28 is perfect. The number 6 is also perfect, since sigma(6) = 3 x 4 = 12.
This gives a useful check. Factors come in pairs (d, n/d), and the sum is always greater than n when n is greater than 1. If your answer is less than n + 1, something is wrong. For a prime n the sum is exactly n + 1.
Common errors
- Forgetting the 1 in each bracket. The bracket for 2^3 is 1 + 2 + 4 + 8, not 2 + 4 + 8, unless you are deliberately excluding the power 2^0.
- Using the factor-count rule by mistake. The count multiplies (e + 1), but the sum multiplies full brackets. For 360 the count is 4 x 3 x 2 = 24, while the sum is 1170.
- Adding sums for different primes. The brackets must be multiplied, not added.
- Applying the formula to a number with a repeated prime listed twice. Combine them first, so 12 = 2^2 x 3 and not 2 x 2 x 3.
- Mixing up "proper factors" definitions. Check whether 1 or n is excluded.
- Reading the formula for a prime power incorrectly. For p^e alone, sigma is 1 + p + ... + p^e, which is one bracket and nothing more.
Strategy for CAT
- Factorize once, and keep the factorization visible.
- Write each bracket as a list, so you can modify it for odd, even, multiple-of or square variants.
- Multiply the smaller brackets first to keep the arithmetic easy, as in 6 x 13 = 78 before multiplying by 15.
- Run the sanity check that the answer exceeds n.
Exercise
Find the sum of all factors of 600, and then the sum of those factors of 600 that are odd.
Show answer
600 = 2^3 x 3 x 5^2. Brackets: for 2 it is 1 + 2 + 4 + 8 = 15, for 3 it is 1 + 3 = 4, for 5 it is 1 + 5 + 25 = 31. The sum of all factors is 15 x 4 x 31 = 1860. The odd factors drop the bracket for 2, so the sum is 4 x 31 = 124.
Exercise
Find the sum of the factors of 360 that are multiples of 10.
Show answer
A multiple of 10 needs at least one 2 and at least one 5. For 360 = 2^3 x 3^2 x 5, the 2 bracket is 2 + 4 + 8 = 14, the 3 bracket is 1 + 3 + 9 = 13, and the 5 bracket is 5 alone. The sum is 14 x 13 x 5 = 910.
Exercise
A number has the form 2^a x 3, and the sum of its factors is 63. Find the number.
Show answer
The sum is (2^(a+1) - 1) x 4 = 63, which is not possible because 63 is not divisible by 4. So no number of this form has factor sum 63. Check a different form: if the number is 2^a alone, the sum is 2^(a+1) - 1 = 63, so a = 5 and the number is 32.