1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <iostream> #include <cmath> #define maxn 1000010 #define ll long long using namespace std;
const ll p = 4179340454199820289; inline ll mul(ll x, ll y) { return (x * y - (ll) ((long double) x / p * y) * p + p) % p; } inline ll add(ll x, ll y) { return (x += y) >= p ? x - p : x; } ll pow_mod(ll x, ll n) { ll s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; }
const int N = 1000000;
int pri[maxn], cnt; bool isp[maxn]; void init_isp(int n) { for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) break; } } }
ll inv[maxn]; void init_inv(int n) { inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = mul(p - (p / i), inv[p % i]); }
const ll inv2 = pow_mod(2, p - 2); inline ll F1(ll n) { return mul(n, mul(n + 1, inv2)); } inline ll ch(ll pk, int k) { return p - mul(pk, mul(inv[k], inv[k - 1])); }
ll n;
ll dfs(int k, ll m, ll h) { ll ans = mul(h, F1(n / m)); for (ll res = n / m; 1ll * pri[k] * pri[k] <= res && k <= cnt; ++k) for (ll e = 2, t = 1ll * pri[k] * pri[k]; t <= res; t *= pri[k], ++e) ans = add(ans, dfs(k + 1, m * t, mul(h, ch(t, e)))); return ans; }
void work() { cin >> n; cout << mul(dfs(1, 1, 1), pow_mod(n, p - 2)) << "\n"; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int T; cin >> T; init_isp(N); init_inv(N); while (T--) work(); return 0; }
|