the question link : CIELRCPT Problem - CodeChef
WA link : CodeChef: Practical coding for everyone
Just use braces in the while loop, Your code is considering 2048 only once.
Moreover, the answer is simple ans = p/2048 + countSetBits(p%2048).
You can use pre-defined function for counting Set Bits.
yes, the error was i did not used the braces and so the items did not incremented.