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.
Here is a tip, a number's divisor will always be 1 and the number itself.
So you can initialize the sum as n+1 itself.
And the start the loop from i=2 till i<=n/2 because the greatest divisor of the number will not be greater than its half. Hence by this you shorten your for loop.
Also place a condition at start for n=1 then just return 1. Otherwise that test case wont be successful
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
Here is a tip, a number's divisor will always be 1 and the number itself. So you can initialize the sum as n+1 itself. And the start the loop from i=2 till i<=n/2 because the greatest divisor of the number will not be greater than its half. Hence by this you shorten your for loop. Also place a condition at start for n=1 then just return 1. Otherwise that test case wont be successful