link:
http://www.spoj.pl/problems/NEG2/
i tried the following solution for the above problem but i am getting TLE please help
#include<iostream>
using namespace std;
void convert(int n)
{
string s="";
if(n==0)
{
printf("0\n");
return;
}
int i=-2;
while(n)
{
if(n%i<0)
{
s=(char)(((n%i)+2)+'0')+s;
n=(n/i)+1;
}
else
{
s=(char)((n%i)+'0')+s;
n=n/i;
}
}
cout<<s;
cout<<"\n";
}
int main()
{
int t;
scanf("%d",&t);
int n;
while(t--)
{
scanf("%d",&n);
convert(n);
}
}