Why Codechef not accepting my code even when i am getting the correct output in many of my codes??

For eg: ciel and receipt
link: https://www.codechef.com/problems/CIELRCPT

#include

using namespace std;

int main()
{
int t,i,counts,items;
long int p[5],n;
cin>>t;
for(i=0;i<t;i++)
{
cin>>p[i];
}
for(i=0;i<t;i++)
{
counts= 0;
n=p[i];
while(n!=0)
{
if(n>=2048)
{
items=n/2048;
counts+=items;
n=n-(2048items);
}
else if(n>=1024)
{
items=n/1024;
counts+=items;
n=n-(1048
items);
}
else if(n>=512)
{
items=n/512;
counts+=items;
n=n-(512items);
}
else if(n>=256)
{
items=n/256;
counts+=items;
n=n-(256
items);
}
else if(n>=128)
{
items=n/128;
counts+=items;
n=n-(128items);
}
else if(n>=64)
{
items=n/64;
counts+=items;
n=n-(64
items);
}
else if(n>=32)
{
items=n/32;
counts+=items;
n=n-(32items);
}
else if(n>=16)
{
items=n/16;
counts+=items;
n=n-(16
items);
}
else if(n>=8)
{
items=n/8;
counts+=items;
n=n-(8items);
}
else if(n>=4)
{
items=n/4;
counts+=items;
n=n-(4
items);
}
else if(n>=2)
{
items=n/2;
counts+=items;
n=n-(2items);
}
else if(n>=1)
{
items=n/1;
counts+=items;
n=n-(1
items);
}
}
cout<<counts<<endl;
}
return 0;
}

There’s a small mistake in your submission, “n=n-(1048*items)” I have submitted your solution after changing that to 1024 and got AC

1 Like

can u please give the link to your submission on ideone or codechef…

oh i didn’t see that. Thnxx.