// Zball in Tina Town.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define PI 3.1415926535897932626 #define EXIT exit(0); #define PAUSE system("pause"); #define DEBUG puts("Here is a BUG"); #define SYNC_CLOSE ios::sync_with_stdio(false); #define what_is(x) cout << #x << " is " << x << endl; #define CLEAR(name, init) memset(name, init, sizeof(name)); const double eps = 1e-8; const int MAXN = (int)1e5 + 5; using namespace std; bool flag[MAXN]; int k = 0; LL prime[MAXN]; void init(void) { k = 0; for(int i = 2; i < MAXN; i++) { if (!flag[i]) { prime[k++] = i; for(int j = 2*i; j < MAXN; j += i) { flag[j] = true; } } } } inline bool isPrime(LL n) { for(int i = 0; prime[i]*prime[i] <= n; i++) { if (n % prime[i] == 0) return false; } return true; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("D:\\Documents\\Disk_Synchronous\\Programs\\Acm\\input.txt", "r", stdin); #endif init(); int T; cin >> T; while(T--) { int n; scanf("%d", &n); if (n == 4) puts("2"); else if (isPrime(n)) printf("%d\n", n - 1); else puts("0"); } return 0; }