GETTING WA IN ARRANGING CUPCAKES

The problem: http://discuss.codechef.com/problems/RESQ
my solution: https://www.codechef.com/viewsolution/25042312
which test case is going wrong?

The extra condition that you have put in line 42 is wrong. The answer for 1 is 0.

Also, don’t use for( int i=1; i<=sqrt(n); ++i ). This will cause precision issues for larger n. Instead use for( int i=1; i*i <= n; ++i ). If n is greater than 2^{15}, you’ll need to store i as a 64 bit integer.

1 Like

Thanks got AC after ur suggestions. So we should avoid the use of sqrt() as long as possible?

I would say avoid floats as much as possible unless the question absolutely requires them. I realized I don’t know how to handle them after attempting RECTLOVE. You can try that problem to see just how weird they are.

Problem setters also know this and I think they also make questions that don’t require floats at all. A recent example would be this.