My opinion is, that sharing variable for different loop is very bad habit.
I changed just this without algorithm modification and it seems to work fine now - http://ideone.com/CDZ3l0
I think, that
for (z - 1; z > 0; --z)
is the problem, modify it to
for (; z > 0; --z)
z = y - 1
[Here’s] my new code. I am still getting TLE status so I checked the accepted solutions and found [this one] . Even he is iterating over the same range, but only my code is getting TLE. Someone please explain this and also tell me the complexities of the two codes and how are they different.
In ur code u r printing ‘sum-n’ but in the question you have to print summation of all divisors that is ‘sum’ u r calculating in ur code…and also the number itself is not counted as a divisor so u hv to print ‘sum-1’…
@betlista Thanks a lot. “sharing variable for different loop is very bad habit” I do not understand what you re trying to say.
@junior94 Thanks but I had already figured that out some time ago. Could you please look at my post below this and try answering it.