#6682. 梦中的数论
推式子
∑i=1n∑j=kn∑k=1n[(j∣i)∧((j+k)∣i)]显然有j+k>j,所以我们另j+k=k′,有j>k′,并且j,k′都是i的约数这就相当于在σ(i)中选取一对有序对了,所以总的选法有C(σ(i),2)种原式=∑i=1nσ(i)(σ(i)−1)2∑i=1nσ2(i)−∑i=1nσ(i)2∑i=1nσ(i)=∑i=1n∑j∣i=∑i=1nni,数论分块即可求解∑i=1nσ2(i):i∈prime,σ2(p)=4,σ2(pe)=(e+1)2并且这是一个积函数,所以我们显然可以用Min25筛求解\sum_{i = 1} ^{n} \sum_{j = k} ^{n} \sum_{k = 1} ^{n}[(j \mid i) \wedge ((j + k) \mid i)]\\ 显然有j + k > j,所以我们另j + k = k',有j > k',并且j, k'都是i的约数\\ 这就相当于在\sigma(i)中选取一对有序对了,所以总的选法有C(\sigma(i), 2)种\\ 原式 = \sum_{i = 1} ^{n} \frac{\sigma(i)(\sigma(i) - 1)}{2}\\ \frac{\sum_{i = 1} ^{n} \sigma ^2(i) - \sum_{i = 1} ^{n} \sigma(i)}{2}\\ \sum_{i = 1} ^{n} \sigma(i) = \sum_{i = 1} ^{n} \sum_{j \mid i} = \sum_{i = 1} ^{n} \frac{n}{i},数论分块即可求解\\ \sum_{i = 1} ^{n} \sigma ^2(i):\\ i \in prime, \sigma ^ 2(p) = 4, \sigma ^ 2(p ^ e) = (e + 1) ^2\\ 并且这是一个积函数,所以我们显然可以用Min25筛求解\\ i=1∑nj=k∑nk=1∑n[(j∣i)∧((j+k)∣i)]显然有j+k>j,所以我们另j+k=k′,有j>k′,并且j,k′都是i的约数这就相当于在σ(i)中选取一对有序对了,所以总的选法有C(σ(i),2)种原式=i=1∑n2σ(i)(σ(i)−1)2∑i=1nσ2(i)−∑i=1nσ(i)i=1∑nσ(i)=i=1∑nj∣i∑=i=1∑nin,数论分块即可求解i=1∑nσ2(i):i∈prime,σ2(p)=4,σ2(pe)=(e+1)2并且这是一个积函数,所以我们显然可以用Min25筛求解
代码
/*Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>#define mp make_pair
#define pb push_back
#define endl '\n'
#define mid (l + r >> 1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define ls rt << 1
#define rs rt << 1 | 1using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;const double pi = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N = 1e6 + 10, mod = 998244353, inv2 = mod + 1 >> 1;namespace Min_25 {int prime[N], id1[N], id2[N], m, cnt, T;ll a[N], g[N], sum[N], n;bool st[N];int ID(ll x) {return x <= T ? id1[x] : id2[n / x];}void init() {T = sqrt(n + 0.5);cnt = 0, m = 0;for(int i = 2; i <= T; i++) {if(!st[i]) {prime[++cnt] = i;sum[cnt] = (sum[cnt - 1] + 4) % mod;}for(int j = 1; j <= cnt && 1ll * i * prime[j] <= T; j++) {st[i * prime[j]] = 1;if(i % prime[j] == 0) {break;}}}for(ll l = 1, r; l <= n; l = r + 1) {r = n / (n / l);a[++m] = n / l;if(a[m] <= T) id1[a[m]] = m;else id2[n / a[m]] = m;g[m] = (4ll * a[m] - 4) % mod;}for(int j = 1; j <= cnt; j++) {for(int i = 1; i <= m && 1ll * prime[j] * prime[j] <= a[i]; i++) {g[i] = ((g[i] - (g[ID(a[i] / prime[j])] - sum[j - 1]) % mod) % mod + mod) % mod;}}for(int i = 1; i <= T; i++) {st[i] = 0;}}ll solve(ll n, int m) {if(n < prime[m]) return 0;ll ans = (g[ID(n)] - sum[m - 1] % mod + mod) % mod;for(int j = m; j <= cnt && 1ll * prime[j] * prime[j] <= n; j++) {for(ll i = prime[j], e = 1; i * prime[j] <= n; i *= prime[j], e++) {ans = (ans + (e + 1) * (e + 1) % mod * (solve(n / i, j + 1)) % mod + (e + 2) * (e + 2) % mod) % mod;}}return ans;}ll solve(ll x) {if(x <= 1) return x;n = x;init();return solve(x, 1) + 1;}
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);ll n = read(), ans = 0;for(ll l = 1, r; l <= n; l = r + 1) {r = n / (n / l);ans = (ans + (r - l + 1) % mod * ((n / l) % mod) % mod) % mod;}ans = (Min_25::solve(n) - ans) % mod * inv2 % mod;ans = (ans % mod + mod) % mod;cout << ans << endl;return 0;
}