/* -*- coding: utf-8 -*- * * 2016.cc: No.2016 Countdown Divisors - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_P = 32000; /* typedef */ typedef vector vi; /* global variables */ bool primes[MAX_P + 1]; /* subroutines */ int gen_primes(int maxp, vi &pnums) { fill(primes, primes + maxp + 1, true); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); return (int)pnums.size(); } int divnum(int n, vi &pnums) { int d = 1; int pn = pnums.size(); for (int i = 0; i < pn; i++) { int pi = pnums[i]; if (pi * pi > n) { if (n > 1) d *= 2; break; } if (n % pi == 0) { int fi = 0; while (n % pi == 0) n /= pi, fi++; d *= fi + 1; } } return d; } /* subroutines */ /* main */ int main() { vi pnums; gen_primes(MAX_P, pnums); int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); while (n > 2) n -= divnum(n, pnums); printf("%d\n", n); } return 0; }