Sub topic 1
Divisibility, Factors and Multiples
Prerequisites
You should be comfortable with integer multiplication and division with remainder, and with exponent notation such as 2^3 = 8. This chapter uses the Python snippet at the end, so basic Python reading helps.
Divisibility, factors and multiples
If a divides b with no remainder, then a is a factor of b and b is a multiple of a. For example, 6 is a factor of 36, and 36 is a multiple of 6. Every number has 1 and itself as factors.
Divisibility rules
Divisibility rules let you test a number without long division.
- 2: the last digit is even.
- 3: the digit sum is divisible by 3.
- 4: the last two digits form a multiple of 4.
- 5: the last digit is 0 or 5.
- 6: the number is divisible by both 2 and 3.
- 7: double the last digit, subtract it from the rest, and repeat. For 343, compute 34 - 6 = 28, which is divisible by 7.
- 8: the last three digits form a multiple of 8.
- 9: the digit sum is divisible by 9.
- 10: the last digit is 0.
- 11: the alternating sum of the digits is divisible by 11.
- 12: the number is divisible by both 3 and 4.
- 13: add 4 times the last digit to the rest. For 91, compute 9 + 4 = 13.
Primes, composites and coprime numbers
A prime has exactly two factors: 1 and itself. A composite has more than two factors. Two numbers are coprime when their highest common factor is 1, as with 8 and 15.
Prime factorization
Prime factorization writes a number as a product of primes. Write 360 as 2^3 × 3^2 × 5. This form shows every factor at a glance and drives most later methods in this tutorial.
def prime_factors(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
print(prime_factors(360)) # {2: 3, 3: 2, 5: 1}Counting factors
Once you have the prime form n = p1^e1 × p2^e2 × ..., the number of factors is the product of (e + 1) for each prime. For 360 = 2^3 × 3^2 × 5^1, the count is (3 + 1)(2 + 1)(1 + 1) = 24.
Exercise
How many factors does 72 have?
Show answer
72 = 2^3 × 3^2, so the count is (3 + 1)(2 + 1) = 12.