What are the divisors of 1004?

1, 2, 4, 251, 502, 1004

4 even divisors

2, 4, 502, 1004

2 odd divisors

1, 251

How to compute the divisors of 1004?

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 1004 by each of the numbers from 1 to 1004 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)

  • 1004 / 1 = 1004 (the remainder is 0, so 1 is a divisor of 1004)
  • 1004 / 2 = 502 (the remainder is 0, so 2 is a divisor of 1004)
  • 1004 / 3 = 334.66666666667 (the remainder is 2, so 3 is not a divisor of 1004)
  • ...
  • 1004 / 1003 = 1.0009970089731 (the remainder is 1, so 1003 is not a divisor of 1004)
  • 1004 / 1004 = 1 (the remainder is 0, so 1004 is a divisor of 1004)

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 1004 (i.e. 31.68595903551). 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 )

  • 1004 / 1 = 1004 (the remainder is 0, so 1 and 1004 are divisors of 1004)
  • 1004 / 2 = 502 (the remainder is 0, so 2 and 502 are divisors of 1004)
  • 1004 / 3 = 334.66666666667 (the remainder is 2, so 3 is not a divisor of 1004)
  • ...
  • 1004 / 30 = 33.466666666667 (the remainder is 14, so 30 is not a divisor of 1004)
  • 1004 / 31 = 32.387096774194 (the remainder is 12, so 31 is not a divisor of 1004)