#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 100005; #define N 100000 LL a[maxn]; int p[maxn]; int cnt; void init() { for(int i = 2; i <= N; i++) if(p[i] == 0) for(int j = i + i; j <= N; j += i) p[j] = 1; cnt = 0; for(int i = 2; i <= N; i++) if(p[i] == 0) a[cnt++] = i; } bool check(LL t) { for(LL i = 0; a[i] * a[i] <= t; i++) { if(t % a[i] == 0) { t /= a[i]; if(t % a[i] == 0) return false; } } return true; } void work() { LL x, y; scanf("%lld", &y); LL t = sqrt(y); LL ans = y + 100; for(LL i = max((LL)2, t - 200); i <= t + 200; i++) if(check(i)) { ans = min(ans, abs(y - i * i)); } printf("%lld\n", ans); } int main() { init(); int _; scanf("%d", &_); while(_--) work(); return 0; }