#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; const int S=10;//随机算法判定次数,S越大,判错概率越小 inline long long mult_mod(long long a,long long b,long long c) { ll re = (a * b - (ll) ((long double) a / c * b + 1e-8) * c); return re < 0 ? re + c : re; } inline long long pow_mod(long long x,long long n,long long mod)//x^n%c { if(n==1)return x%mod; x%=mod; long long tmp=x; long long ret=1; while(n) { if(n&1) ret=mult_mod(ret,tmp,mod); tmp=mult_mod(tmp,tmp,mod); n>>=1; } return ret; } inline bool check(long long a,long long n,long long x,long long t) { long long ret=pow_mod(a,x,n); long long last=ret; for(int i=1;i<=t;i++) { ret=mult_mod(ret,ret,n); if(ret==1&&last!=1&&last!=n-1) return true;//合数 last=ret; } if(ret!=1) return true; return false; } inline bool Miller_Rabin(long long n) { if(n<2)return false; if(n==2)return true; if((n&1)==0) return false;//偶数 long long x=n-1; long long t=0; while((x&1)==0){x>>=1;t++;} for(int i=0;i=n)p=Pollard_rho(p,rand()%(n-1)+1); findfac(p); findfac(n/p); } ll Abs(ll a) { return a < 0 ? -a : a; } ll Main() { ll a; scanf("%I64d", &a); if (a == 1) return 3; if (a == 2) return 2; if (a == 3) return 1; if (a == 4) return 0; if (a == 5) return 1; if (a == 6) return 2; if (a == 7) return 2; if (a == 8) return 1; if (a == 9) return 0; if (a == 10) return 1; if (a == 11) return 2; if (a == 12) return 3; ll Ans = 1e18, num = 0; ll b = ll(sqrt((double)a) + 0.5); for (ll ans = 0; ans < 100000000; ans++) { if (b - ans > 0) { tol = 0; findfac(b - ans); sort(factor, factor + tol); if (unique(factor, factor + tol) - factor == tol) { Ans = min(Ans, Abs(a - (b - ans) * (b - ans))); num++; if (num == 4) return Ans; } } { tol = 0; findfac(b + ans); sort(factor, factor + tol); if (unique(factor, factor + tol) - factor == tol) { Ans = min(Ans, Abs(a - (b + ans) * (b + ans))); num++; if (num == 4) return Ans; } } } } int main() { ll T; scanf("%I64d", &T); while (T--) printf("%I64d\n", Main()); }