• + 2 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