#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; /* 考察 dist(i,j)= 1(gcd(i,j)=1) 2(else) */ // phi[0] ... phi[n] を前計算する O(n log(log(n))) // phi[i] = i以下であって、iと互いに素な数の個数 // ref: https://qiita.com/drken/items/3beb679e54266f20ab63 // ref: https://manabitimes.jp/math/667 // 公式: phi[n] = n * Π(1-1/p) (pはnの素因数) // 公式: phi[n]phi[m] = phi[nm] (nとmが互いに素) // 公式: Σ(d|n)phi[d] = n // 公式: a^phi(m) ≡ 1 (mod m) (aとmが互いに素) vector totientTable(ll n) { vector ret(n + 1); iota(ret.begin(), ret.end(), 0); for (ll i = 2; i <= n; i++) { if (ret[i] == i) { for (ll j = i; j <= n; j += i) ret[j] = ret[j] / i * (i - 1); } } return ret; } int main() { int T; cin >> T; const int mx = 1e7 + 5; auto tot = totientTable(mx); tot[1]--; vector pref(mx + 1); for (int i = 1; i < mx; i++) pref[i + 1] = pref[i] + tot[i] + (i - tot[i] - 1) * 2; while (T--) { int N; cin >> N; cout << pref[N + 1] << '\n'; } }