Sub topic 6
Sum of Factors
Prerequisites and the main idea
Assume you can multiply integers, use exponent notation, and write a number as a product of primes. A factor, or divisor, is a positive integer that divides another integer exactly.
The prime factorization of a number gives a direct way to find the sum of all its positive factors. If
\[ n=p1^{e1}p2^{e2}\cdots pk^{ek}, \]
where the \(p_i\) are distinct primes, then
\[ \sigma(n)= \left(1+p1+p1^2+\cdots+p1^{e1}\right) \cdots \left(1+pk+pk^2+\cdots+pk^{ek}\right). \]
Using the geometric-series formula, this becomes
\[ \sigma(n)= \prod{i=1}^{k}\frac{pi^{ei+1}-1}{pi-1}. \]
Here, \(\sigma(n)\) means the sum of the positive factors of \(n\).
Worked example
Find the sum of the factors of \(360\).
First write 360 in prime-power form:
\[ 360=2^3\cdot3^2\cdot5. \]
For the prime 2, choose one of \(1,2,2^2,2^3\). Their sum is
\[ 1+2+4+8=15. \]
For the prime 3, choose one of \(1,3,3^2\). Their sum is
\[ 1+3+9=13. \]
For the prime 5, choose one of \(1,5\). Their sum is
\[ 1+5=6. \]
Therefore,
\[ \sigma(360)=15\cdot13\cdot6=1170. \]
This multiplication works because every factor of 360 has the form \(2^a3^b5^c\), where \(0\leq a\leq3\), \(0\leq b\leq2\), and \(0\leq c\leq1\).
| Prime power | Possible contributions | Sum |
|---|---|---|
| \(2^3\) | \(1,2,4,8\) | 15 |
| \(3^2\) | \(1,3,9\) | 13 |
| \(5^1\) | \(1,5\) | 6 |
Efficient calculation and common errors
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
def sum_of_factors(n):
total = 1
for p, e in factorize(n).items():
total *= (p ** (e + 1) - 1) // (p - 1)
return total
print(sum_of_factors(360)) # 1170A frequent error is to add only the distinct prime factors. For 360, \(2+3+5=10\), which is not the required sum. Another error is to forget the factor 1. The formula includes it automatically.
The function \(\sigma(n)\) is multiplicative for coprime numbers: if \(\gcd(a,b)=1\), then
\[ \sigma(ab)=\sigma(a)\sigma(b). \]
This rule does not generally work when \(a\) and \(b\) share a prime factor.
Exercise
Find the sum of the positive factors of 72.
Show answer
Since 72 = 2^3 × 3^2, the sum is (1 + 2 + 4 + 8)(1 + 3 + 9) = 15 × 13 = 195.