/* -*- coding: utf-8 -*- * * 2249.cc: No.2249 GCDistance - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 10000000; const int MAX_P = 3200; /* typedef */ typedef long long ll; typedef vector vi; typedef pair pii; typedef vector vpii; /* global variables */ bool primes[MAX_P + 1]; ll ans[MAX_N + 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(); } bool prime_decomp(int n, vi &pnums, vpii& pds) { pds.clear(); int pn = pnums.size(); for (int i = 0; i < pn; i++) { int pi = pnums[i]; if (pi * pi > n) { if (n > 1) pds.push_back(pii(n, 1)); return true; } if (n % pi == 0) { int fi = 0; while (n % pi == 0) n /= pi, fi++; pds.push_back(pii(pi, fi)); } } return false; } int powi(int a, int b) { int p = 1; while (b > 0) { if (b & 1) p *= a; a *= a; b >>= 1; } return p; } int phi(int n, vi &pnums) { vpii pds; prime_decomp(n, pnums, pds); int p = 1; for (auto &pd: pds) { int e = powi(pd.first, pd.second - 1); int s = e * pd.first - e; p *= s; } return p; } /* main */ int main() { vi pnums; gen_primes(MAX_P, pnums); for (int n = 2; n <= MAX_N; n++) { int p = phi(n, pnums); int s = p + (n - 1 - p) * 2; ans[n] = ans[n - 1] + s; } int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); printf("%lld\n", ans[n]); } return 0; }