Lesson 8 – Prime and composite numbers – CountFactors demo task solution code written in php. Gives 100/100 score at the time of publishing.
The description of the problem is copyrighted, so please see the following link for it: https://codility.com/demo/take-sample-test/count_factors
Solution in php:
function solution($N) { $result = 0; $sqrtN = intval(sqrt($N)); $i = 1; while($i <= $sqrtN){ if($N % $i == 0){ $result += 2; } $i++; } if($sqrtN * $sqrtN == $N){ $result--; } return $result; }
Given “AS IS”, can be ported from other languages from solutions found on the internet, please use with care.
Please note: we think that codility.com does not give a correct assessment of your real-world programming skills. For instance, reading the below would bring more understanding why: http://x20x.co.uk/2014/02/why-i-refuse-to-use-codility-and-so-should-you/