What are the divisors of 342?

1, 2, 3, 6, 9, 18, 19, 38, 57, 114, 171, 342

6 even divisors

2, 6, 18, 38, 114, 342

6 odd divisors

1, 3, 9, 19, 57, 171

How to compute the divisors of 342?

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

  • 342 / 1 = 342 (the remainder is 0, so 1 is a divisor of 342)
  • 342 / 2 = 171 (the remainder is 0, so 2 is a divisor of 342)
  • 342 / 3 = 114 (the remainder is 0, so 3 is a divisor of 342)
  • ...
  • 342 / 341 = 1.0029325513196 (the remainder is 1, so 341 is not a divisor of 342)
  • 342 / 342 = 1 (the remainder is 0, so 342 is a divisor of 342)

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 342 (i.e. 18.493242008907). 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 )

  • 342 / 1 = 342 (the remainder is 0, so 1 and 342 are divisors of 342)
  • 342 / 2 = 171 (the remainder is 0, so 2 and 171 are divisors of 342)
  • 342 / 3 = 114 (the remainder is 0, so 3 and 114 are divisors of 342)
  • ...
  • 342 / 17 = 20.117647058824 (the remainder is 2, so 17 is not a divisor of 342)
  • 342 / 18 = 19 (the remainder is 0, so 18 and 19 are divisors of 342)