I tested all the test cases given and various other too and every time I got the right answer but when I submitted it , it showed wrong answer . Could some one please shed some light on my mistakes .
problem: http://www.codechef.com/problems/CIELRCPT

My code(java):

public class CEILRCPT
{

public static void main(String[] args)

``````{

Scanner input = new Scanner(System.in);

int t= input.nextInt();

while(t!=0)

{

int c=0;

double p=input.nextDouble();

for(double i=11.0 ; i>=0.0&&p!=0;i--)

{

double e=Math.pow(2.0,i);

if(p<e)

continue;

else if(p%e==0)

{

p=p-e;

c++;

i++;

}

else

{

c++;

p=p-e;

}

}

System.out.println(c);

t--;

}

}
``````

}

Check your output for case 100000 yours gives 3005 but the answer is 52. Just figure it out. For easy code you can have a look at http://www.codechef.com/viewsolution/5886586

In the last else condition you again need to give i++ because say case is greater than 2048 eg 4097 then in your code 4097 is reduced by only 2048 and i is decreased by 1 unit. So in the next loop the value will be checked by 1024 which is wrong. 4097%2048 !=0 but this does not mean that this can reduce 4097 only by one power. So give i++ in the next else condition also. This is accepted version of ur code - http://www.codechef.com/viewsolution/7044822

Thank you so much man , you saved the day !!