We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

This range doesn't make any sense.
After the middle you don't need to check all values. You should have taken the range(1, n//2+1).
And the beginning value of summ is n. Because the number can always be divided by itself.

That is still not very good - You should only go to sqrt(n) + 1. It really makes the difference - try running it for some little bigger number like 1 billion or more - it is more than 10000 times slower then it could be for 1 billion for example :)
Of course when going only to sqrt(n) + 1, You need to do an extra step, but You will come up with it

## Day 19: Interfaces

You are viewing a single comment's thread. Return to all comments →

This range doesn't make any sense. After the middle you don't need to check all values. You should have taken the range(1, n//2+1). And the beginning value of summ is n. Because the number can always be divided by itself.

You are right, then

That is still not very good - You should only go to sqrt(n) + 1. It really makes the difference - try running it for some little bigger number like 1 billion or more - it is more than 10000 times slower then it could be for 1 billion for example :) Of course when going only to sqrt(n) + 1, You need to do an extra step, but You will come up with it

Good point.