Lady Layton with Math
∑i=1n∑j=1nϕ(gcd(i,j))∑d=1nϕ(d)∑i=1n∑j=1n[gcd(i,j)=d]∑d=1nϕ(d)∑i=1nd∑j=1nd[gcd(i,j)=1]∑d=1nϕ(d)(2∑i=1nd∑j=1i[gcd(i,j)=1]−1)∑d=1nϕ(d)(2∑i=1ndϕ(i)−1)\sum_{i = 1} ^{n} \sum_{j = 1} ^{n} \phi(gcd(i, j))\\ \sum_{d = 1} ^{n} \phi(d) \sum_{i = 1} ^{n} \sum_{j = 1} ^{n} [gcd(i, j) = d]\\ \sum_{d = 1} ^{n} \phi(d) \sum_{i = 1} ^{\frac{n}{d}} \sum_{j = 1} ^{\frac{n}{d}} [gcd(i, j) = 1]\\ \sum_{d = 1} ^{n} \phi(d) \left(2 \sum_{i = 1} ^{\frac{n}{d}} \sum_{j = 1} ^{i} [gcd(i, j) = 1] - 1 \right)\\ \sum_{d = 1} ^{n} \phi(d)\left(2 \sum_{i = 1} ^{\frac{n}{d}} \phi(i) - 1 \right)\\ i=1∑nj=1∑nϕ(gcd(i,j))d=1∑nϕ(d)i=1∑nj=1∑n[gcd(i,j)=d]d=1∑nϕ(d)i=1∑dnj=1∑dn[gcd(i,j)=1]d=1∑nϕ(d)⎝⎛2i=1∑dnj=1∑i[gcd(i,j)=1]−1⎠⎞d=1∑nϕ(d)⎝⎛2i=1∑dnϕ(i)−1⎠⎞
/*Author : lifehappy
*/
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 2e6 + 10, mod = 1e9 + 7;int prime[N], cnt, n;ll phi[N];bool st[N];void init() {phi[1] = 1;for(int i = 2; i < N; i++) {if(!st[i]) {prime[++cnt] = i;phi[i] = i - 1;}for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {st[i * prime[j]] = 1;if(i % prime[j] == 0) {phi[i * prime[j]] = phi[i] * prime[j];break;}phi[i * prime[j]] = phi[i] * (prime[j] - 1);}}for(int i = 1; i < N; i++) {phi[i] = (phi[i] + phi[i - 1]) % mod;}
}unordered_map<int, ll> ans_s;ll Djs(int n) {if(n < N) return phi[n];if(ans_s.count(n)) return ans_s[n];ll ans = 1ll * n * (n + 1) / 2 % mod;for(int l = 2, r; l <= n; l = r + 1) {r = n / (n / l);ans = (ans - (r - l + 1) * Djs(n / l) % mod + mod) % mod;}return ans_s[n] = ans;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int T;init();scanf("%d", &T);while(T--) {ll ans = 0;scanf("%d", &n);for(int l = 1, r; l <= n; l = r + 1) {r = n / (n / l);ans = (ans + 1ll * (Djs(r) - Djs(l - 1)) * (2ll * Djs(n / l) - 1) % mod + mod) % mod;}printf("%lld\n", ans);}return 0;
}