What are the divisors of 1998?

1, 2, 3, 6, 9, 18, 27, 37, 54, 74, 111, 222, 333, 666, 999, 1998

8 even divisors

2, 6, 18, 54, 74, 222, 666, 1998

8 odd divisors

1, 3, 9, 27, 37, 111, 333, 999

How to compute the divisors of 1998?

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

  • 1998 / 1 = 1998 (the remainder is 0, so 1 is a divisor of 1998)
  • 1998 / 2 = 999 (the remainder is 0, so 2 is a divisor of 1998)
  • 1998 / 3 = 666 (the remainder is 0, so 3 is a divisor of 1998)
  • ...
  • 1998 / 1997 = 1.0005007511267 (the remainder is 1, so 1997 is not a divisor of 1998)
  • 1998 / 1998 = 1 (the remainder is 0, so 1998 is a divisor of 1998)

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 1998 (i.e. 44.698993277254). 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 )

  • 1998 / 1 = 1998 (the remainder is 0, so 1 and 1998 are divisors of 1998)
  • 1998 / 2 = 999 (the remainder is 0, so 2 and 999 are divisors of 1998)
  • 1998 / 3 = 666 (the remainder is 0, so 3 and 666 are divisors of 1998)
  • ...
  • 1998 / 43 = 46.46511627907 (the remainder is 20, so 43 is not a divisor of 1998)
  • 1998 / 44 = 45.409090909091 (the remainder is 18, so 44 is not a divisor of 1998)