/****************************************** Mobarak Hosen Shakil ICE, Islamic University ID: mhiceiuk(all), 29698(LOJ) E-mail: mhiceiuk @ (Gmail/Yahoo/FB) Blog: https://iuconvergent.wordpress.com *******************************************/ #include<bits/stdc++.h> using namespace std; int main() { long long k, x, c, ans=0, d; int tn; scanf("%d", &tn); while(tn--) { scanf("%lld", &k); k=abs(k); if(k==0) { printf("3\n"); } else { c= sqrt(k*2.0); x=c*(c+1)/2; if(x<k) c+=1; for(long long i=c; i<c+10;i++) { x=i*(i+1)/2; d=abs(x-k); /// cout<<x<< " "<<d<<endl; if(d%2==0) { c=i; break; } } printf("%lld\n", c); } if(tn!=0) printf("\n"); } return 0; }
Leave a comment