What are the divisors of 300?

1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 25, 30, 50, 60, 75, 100, 150, 300

12 even divisors

2, 4, 6, 10, 12, 20, 30, 50, 60, 100, 150, 300

6 odd divisors

1, 3, 5, 15, 25, 75

How to compute the divisors of 300?

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

  • 300 / 1 = 300 (the remainder is 0, so 1 is a divisor of 300)
  • 300 / 2 = 150 (the remainder is 0, so 2 is a divisor of 300)
  • 300 / 3 = 100 (the remainder is 0, so 3 is a divisor of 300)
  • ...
  • 300 / 299 = 1.0033444816054 (the remainder is 1, so 299 is not a divisor of 300)
  • 300 / 300 = 1 (the remainder is 0, so 300 is a divisor of 300)

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 300 (i.e. 17.320508075689). 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 )

  • 300 / 1 = 300 (the remainder is 0, so 1 and 300 are divisors of 300)
  • 300 / 2 = 150 (the remainder is 0, so 2 and 150 are divisors of 300)
  • 300 / 3 = 100 (the remainder is 0, so 3 and 100 are divisors of 300)
  • ...
  • 300 / 16 = 18.75 (the remainder is 12, so 16 is not a divisor of 300)
  • 300 / 17 = 17.647058823529 (the remainder is 11, so 17 is not a divisor of 300)