the question link : https://www.codechef.com/problems/CIELRCPT
I got your code accepted
Check it here
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.