brz的函数
/* Author : lifehappy */ #include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10; int prime[N], mu[N], ans[N], cnt, n; bool st[N]; void init() { mu[1] = 1; for(int i = 2; i < N; i++) { if(!st[i]) { prime[++cnt] = i; mu[i] = -1; } for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) { st[i * prime[j]] = 1; if(i % prime[j] == 0) { break; } mu[i * prime[j]] = -mu[i]; } } for(int d = 1; d < N; d++) { int res = 0; for(int l = d; l < N; l += d) { int r = l + d - 1; r = min(r, N - 2); res += mu[l]; ans[l] += mu[d] * res * res; ans[r + 1] -= mu[d] * res * res; } } for(int i = 1; i < N; i++) { ans[i] += ans[i - 1]; } } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); init(); int T; scanf("%d", &T); while(T--) { scanf("%d", &n); printf("%d\n", ans[n]); } return 0; }