What are the divisors of 42?
1, 2, 3, 6, 7, 14, 21, 42
- There is a total of 8 positive divisors.
- The sum of these divisors is 96.
- The arithmetic mean is 12.
4 even divisors
2, 6, 14, 42
4 odd divisors
1, 3, 7, 21
How to compute the divisors of 42?
A number N is said to be divisible by a number M (with M non-zero) if, when we divide N by M, the remainder of the division is zero.
Brute force algorithm
We could start by using a brute-force method which would involve dividing 42 by each of the numbers from 1 to 42 to determine which ones have a remainder equal to 0.
(where is the integer part of the quotient)
- 42 / 1 = 42 (the remainder is 0, so 1 is a divisor of 42)
- 42 / 2 = 21 (the remainder is 0, so 2 is a divisor of 42)
- 42 / 3 = 14 (the remainder is 0, so 3 is a divisor of 42)
- ...
- 42 / 41 = 1.0243902439024 (the remainder is 1, so 41 is not a divisor of 42)
- 42 / 42 = 1 (the remainder is 0, so 42 is a divisor of 42)
Improved algorithm using square-root
However, there is another slightly better approach that reduces the number of iterations by testing only integers less than or equal to the square root of 42 (i.e. 6.4807406984079). Indeed, if a number N has a divisor D greater than its square root, then there is necessarily a smaller divisor d such that:
(thus, if , then )
- 42 / 1 = 42 (the remainder is 0, so 1 and 42 are divisors of 42)
- 42 / 2 = 21 (the remainder is 0, so 2 and 21 are divisors of 42)
- 42 / 3 = 14 (the remainder is 0, so 3 and 14 are divisors of 42)
- ...
- 42 / 5 = 8.4 (the remainder is 2, so 5 is not a divisor of 42)
- 42 / 6 = 7 (the remainder is 0, so 6 and 7 are divisors of 42)