What are the divisors of 500?

1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500

8 even divisors

2, 4, 10, 20, 50, 100, 250, 500

4 odd divisors

1, 5, 25, 125

How to compute the divisors of 500?

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.

N mod M = 0

Brute force algorithm

We could start by using a brute-force method which would involve dividing 500 by each of the numbers from 1 to 500 to determine which ones have a remainder equal to 0.

Remainder = N ( M × N M )

(where N M is the integer part of the quotient)

  • 500 / 1 = 500 (the remainder is 0, so 1 is a divisor of 500)
  • 500 / 2 = 250 (the remainder is 0, so 2 is a divisor of 500)
  • 500 / 3 = 166.66666666667 (the remainder is 2, so 3 is not a divisor of 500)
  • ...
  • 500 / 499 = 1.002004008016 (the remainder is 1, so 499 is not a divisor of 500)
  • 500 / 500 = 1 (the remainder is 0, so 500 is a divisor of 500)

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 500 (i.e. 22.360679774998). Indeed, if a number N has a divisor D greater than its square root, then there is necessarily a smaller divisor d such that:

D × d = N

(thus, if N D = d , then N d = D )

  • 500 / 1 = 500 (the remainder is 0, so 1 and 500 are divisors of 500)
  • 500 / 2 = 250 (the remainder is 0, so 2 and 250 are divisors of 500)
  • 500 / 3 = 166.66666666667 (the remainder is 2, so 3 is not a divisor of 500)
  • ...
  • 500 / 21 = 23.809523809524 (the remainder is 17, so 21 is not a divisor of 500)
  • 500 / 22 = 22.727272727273 (the remainder is 16, so 22 is not a divisor of 500)