What are the divisors of 512?
1, 2, 4, 8, 16, 32, 64, 128, 256, 512
- There is a total of 10 positive divisors.
- The sum of these divisors is 1023.
- The arithmetic mean is 102.3.
9 even divisors
2, 4, 8, 16, 32, 64, 128, 256, 512
1 odd divisors
1
How to compute the divisors of 512?
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 512 by each of the numbers from 1 to 512 to determine which ones have a remainder equal to 0.
(where is the integer part of the quotient)
- 512 / 1 = 512 (the remainder is 0, so 1 is a divisor of 512)
- 512 / 2 = 256 (the remainder is 0, so 2 is a divisor of 512)
- 512 / 3 = 170.66666666667 (the remainder is 2, so 3 is not a divisor of 512)
- ...
- 512 / 511 = 1.0019569471624 (the remainder is 1, so 511 is not a divisor of 512)
- 512 / 512 = 1 (the remainder is 0, so 512 is a divisor of 512)
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 512 (i.e. 22.62741699797). 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 )
- 512 / 1 = 512 (the remainder is 0, so 1 and 512 are divisors of 512)
- 512 / 2 = 256 (the remainder is 0, so 2 and 256 are divisors of 512)
- 512 / 3 = 170.66666666667 (the remainder is 2, so 3 is not a divisor of 512)
- ...
- 512 / 21 = 24.380952380952 (the remainder is 8, so 21 is not a divisor of 512)
- 512 / 22 = 23.272727272727 (the remainder is 6, so 22 is not a divisor of 512)