CHFING - What am I missing?

I am unable to find where my code goes wrong.
https://www.codechef.com/viewsolution/24825260

1 Like

Using // instead of / might make it correct.

1 Like

Their are 2 problems with your code.

First, you are doing / instead of // which will cause precision issues but fixing that alone will not be enough

Second, k-n will not always be positive so your foo function will return the wrong sum. Instead just take k-1 as a and you’re done.

1 Like