http://www.codechef.com/viewsolution/6264205 on which case(s) is my solution failing.
You have these lines of code
sq = sqrt(n);
if (sq == floor(sq + .5))
{
printf("0\n");
continue;
}
in your program.
If you were trying to check if n is a perfect square, then you got it wrong. What you should have checked there is if (sq * sq == n)
Why your code is wrong? Consider an example n = 17.
Now, sq = sqrt(n) = sqrt(17) = 4.12310562562 = 4.1231
floor(sq + 0.5) = floor(4.1231 + 0.5) = floor(4.6231) = 4 = sq.
So, your condition becomes true, and it prints 0. Whereas the correct answer is 16 in this case.
Whenever the decimal part of the square root of a number is between 0 and 0.5, your code will always print the answer as 0. You should only be checking whether decimal part is equal to 0.
I hope this clears your confusion.
### EDIT: I am sorry, I was mistaken. The above explanation is wrong. Hmm, might be precision issues? I will get back, if I get to the root of this. Once again, sorry for wrong explanation.