#include<stdio.h>
#include<math.h>
int main()
{
long int k;
unsigned long int sum,t,i,j;
freopen("in.txt","r",stdin);
cin>>t;
while(t--)
{
cin>>k;
if(!k)
{
if(t)
cout<<3<<endl<<endl;
else
cout<<3<<endl;
continue;
}
if(k<0)k=-1*k;//abslute value
sum=0;
i=int((-1+sqrt(1+8*k))/2);
sum=(i*(i+1))/2;
if(sum==k)
cout<<i<<endl<<endl;
else
for(j=i+1;;j++)
{
sum=(j*(j+1))/2;
if(sum<k)continue;
if((sum-k)%2==0)
{
if(t)
cout<<j<<endl<<endl;
else
cout<<j<<endl;
break;
}
}
}
return(0);
}
No comments:
Post a Comment