# Codility: CountFactors Solution

Lesson 10 Prime and Composite Numbers

## Approach

If number

a
is a divisor of
n
, then
n/a
is also a divisor.

One of these two divisors is less than or equal to

sqrt(n)
.

This could be proven by contradictory. Assume if that were not the case,

n
would be a product of two numbers greater than
sqrt(n)
, which is impossible.

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}function solution(N) {2  let result = 03  let i = 14  while (i * i < N) {5    if (N % i === 0) {6      result += 27    }8    i++9  }10  if (i * i === N) {11    result++12  }13
14  return result15}```

codility

## Next Post

Hackerrank: Frequency Queries

Jan 27, 2021

## Previous Post

Codility: Flags

Jan 26, 2021

Lesson 10 Prime and Composite Numbers

Search Posts