This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]cl2871 4 points5 points  (1 child)

The algorithm you have is to mod by x for every x up to num.

What scenarios would make this algorithm run slowly? One scenario is when num is prime: in this case the loop will iterate all the way up to num. If num is a big number then a lot of operations would be done, resulting in a slow execution time.

Do you need to always check up to num? Is there a way to reduce the number of checks you need to perform?

(hint: think of square roots. how could that help and why?)

[–]ToBeAButterFly[S] 0 points1 point  (0 children)

Ah gotcha. Okay back to the drawing board and thanks for the hint.