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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int maxn = 100; const int mod = 998244353;
int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; b >>= 1; } return ret; }
int facinv[maxn] = {1, 1};
void facinv_ini() { for (int i = 0, fac = 1; i < maxn; ++i, fac = 1ll * fac * i % mod) { facinv[i] = qpow(fac, mod - 2); } }
int lagrange(int *y, int n, int x) { static int prepre[maxn], suf[maxn], *pre = prepre + 1; pre[-1] = suf[n + 1] = 1; for (int i = 0; i <= n; ++i) pre[i] = 1ll * pre[i - 1] * (x - i + mod) % mod; for (int i = n; i >= 0; i--) suf[i] = 1ll * suf[i + 1] * (i - x + mod) % mod; int b = 0; for (int i = 0; i <= n; ++i) { int up = 1ll * pre[i - 1] * suf[i + 1] % mod; int down = 1ll * facinv[i] * facinv[n - i] % mod; b = (b + 1ll * y[i] * up % mod * down) % mod; } return b; }
int sum(int n, int I, ll mx) { static int f[100]; f[0] = 0; f[1] = (1ll * (n + 1) * (I + 1) % mod - (I + 1) + mod) % mod; for (int x = 2; x <= I + 3; x++) { int left = 1ll * (n + 1) * (I + 1) % mod * x % mod; int fenzi = (qpow(x, 2) - qpow(x, I + 3) + mod) % mod; int fenmu = (1 - x + mod) % mod; f[x] = (left - 1ll * fenzi * qpow(fenmu, mod - 2) % mod + mod) % mod; } for (int x = 1; x <= I + 3; x++) { f[x] = (f[x - 1] + f[x]) % mod; } return lagrange(f, I + 3, mx % mod); }
ll _n;
int f(ll x) { __int128 prod = x; int res = 0; while (prod * x <= _n) { prod *= x; res++; } return res; }
ll calcEnd(ll l, ll r) { while (l < r) { ll mid = (l + r + 1) / 2; if (f(l) == f(mid)) { l = mid; } else { r = mid - 1; } } return l; }
int solve(ll n) { int ans = 0; for (ll l = 2, r; l <= n; l = r + 1) { r = calcEnd(l, n); int I = f(l);
int add = (sum(n % mod, I, r) - sum(n % mod, I, l - 1) + mod) % mod; ans = (ans + add) % mod; } return ans; }
int main() { facinv_ini();
ll n; while (cin >> n) { _n = n; for (int i = 0; i < 1e3; i++) { solve(n); } printf("%d\n", solve(n)); } }
|