What are the divisors of 126?
1, 2, 3, 6, 7, 9, 14, 18, 21, 42, 63, 126
- There is a total of 12 positive divisors.
- The sum of these divisors is 312.
- The arithmetic mean is 26.
6 even divisors
2, 6, 14, 18, 42, 126
6 odd divisors
1, 3, 7, 9, 21, 63
How to compute the divisors of 126?
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 126 by each of the numbers from 1 to 126 to determine which ones have a remainder equal to 0.
(where is the integer part of the quotient)
- 126 / 1 = 126 (the remainder is 0, so 1 is a divisor of 126)
- 126 / 2 = 63 (the remainder is 0, so 2 is a divisor of 126)
- 126 / 3 = 42 (the remainder is 0, so 3 is a divisor of 126)
- ...
- 126 / 125 = 1.008 (the remainder is 1, so 125 is not a divisor of 126)
- 126 / 126 = 1 (the remainder is 0, so 126 is a divisor of 126)
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 126 (i.e. 11.224972160322). 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 )
- 126 / 1 = 126 (the remainder is 0, so 1 and 126 are divisors of 126)
- 126 / 2 = 63 (the remainder is 0, so 2 and 63 are divisors of 126)
- 126 / 3 = 42 (the remainder is 0, so 3 and 42 are divisors of 126)
- ...
- 126 / 10 = 12.6 (the remainder is 6, so 10 is not a divisor of 126)
- 126 / 11 = 11.454545454545 (the remainder is 5, so 11 is not a divisor of 126)