Sub topic 2
Sum of factors, HCF and LCM
This chapter assumes you can do integer division with remainder, write numbers in exponent form, and multiply fractions. You should also know how to find prime factors.
Sum of factors
If a number is written as a product of prime powers, n = p1^e1 × p2^e2 × ..., then the number of factors is (e1 + 1)(e2 + 1)..., and the sum of factors is the product of (p^(e+1) − 1)/(p − 1) over each prime.
For 360 = 2^3 × 3^2 × 5:
- Count: 4 × 3 × 2 = 24 factors.
- Sum: (15/1) × (26/2) × (24/4) = 15 × 13 × 6 = 1170.
Factor pairs, perfect squares and odd factor counts
Factors pair up as (d, n/d). Each pair has two different factors unless d = n/d, which happens only when n is a perfect square. A perfect square therefore has an odd count of factors, and any number with an odd count of factors is a perfect square.
> Check this with 36 = 2^2 × 3^2. It has (2+1)(2+1) = 9 factors, which is odd, and 36 = 6^2.
Highest Common Factor (HCF)
The HCF of two numbers is the largest number that divides both. Take the lowest power of each shared prime. For 252 = 2^2 × 3^2 × 7 and 105 = 3 × 5 × 7, the shared primes are 3 and 7, so HCF = 3 × 7 = 21.
Least Common Multiple (LCM)
The LCM is the smallest number that both numbers divide. Take the highest power of every prime that appears. For the same pair, LCM = 2^2 × 3^2 × 5 × 7 = 1260.
Euclid's algorithm for fast HCF
For large numbers, replace (a, b) with (b, a mod b) until the remainder is zero. The last nonzero divisor is the HCF.
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a // gcd(a, b) * b
print(gcd(252, 105), lcm(252, 105)) # 21 1260Exercise
How many factors does 60 have, and what is their sum?
Show answer
60 = 2^2 × 3 × 5. The count is 3 × 2 × 2 = 12. The sum is 7 × 4 × 6 = 168.