Solution to Count-Factors by codility

28 Jul


Question Name: Count-Factors or CountFactors

9 Replies to “Solution to Count-Factors by codility

  1. Hi Sheng! Thanks for share your solutions!
    In this one, I disagree, cause if N=1 the result should be 1 and in this solution return 0.
    Just that!

    • I agree with your conclusion “if N=1 the result should be 1”, but disagree with “this solution return 0”. Actually this solution will return 1, if the input is 1. Please refer to the line #11.

  2. When I run the C# version of your solution through Codility it fails timing on the last LARGE Number test case. As a result I modified it so that the multiplication isn`t performed for each loop in the while.

  3. Java solution

  4. C# Solution – 100%

  5. Result:

  6. My initial approach. I treated differently odd and even numbers. Of course, one can use sqrt and avoiding additional operations. But improving that way, gave me no difference in codility tests.

Leave a Reply

Your email address will not be published.

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!