题解:P9308 「DTOI-5」#1f1e33
令
考虑拆
对
代回原式:
令
/*
* author: LostKeyToReach
* created time: 2026-11-25 10:38:33
*/
#include <bits/stdc++.h>
#define vi std::vector<int>
#define eb emplace_back
using ll = long long;
using pii = std::pair<int, int>;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define chkmax(x, y) x = std::max(x, y)
#define chkmin(x, y) x = std::min(x, y)
int fio = (std::cin.tie(0)->sync_with_stdio(0), 0);
constexpr int N = 1e6 + 5, mod = 998244353;
int n, p[N], A[N], tot, B[N], c[N], phi[N], ans[N];
bool vis[N];
int mul(int x, int y) {
return 1ll * x * y % mod;
}
int add(int x, int y) {
return (x += y) >= mod ? x - mod : x;
}
int sub(int x, int y) {
return (x -= y) < 0 ? x + mod : x;
}
int32_t main() {
std::cin >> n;
for (int i = 1; i <= n; ++i) A[i] = 1;
phi[1] = 1;
for (int i = 2; i <= n; ++i) {
if (!vis[i]) p[++tot] = i, A[i] = mod + 1 - i, phi[i] = i - 1;
for (int j = 1; j <= tot && i * p[j] <= n; ++j) {
vis[i * p[j]] = 1;
if (i % p[j] == 0) {
A[i * p[j]] = A[i];
phi[i * p[j]] = phi[i] * p[j];
break;
}
A[i * p[j]] = mul(A[i], A[p[j]]);
phi[i * p[j]] = phi[i] * phi[p[j]];
}
}
for (int i = 1; i <= n; ++i) A[i] = mul(A[i], i);
for (int i = 2; i <= n; ++i)
for (int j = i; j <= n; j += i)
c[j] = add(c[j], mul(phi[i], j / i));
for (int i = 1, s1 = 0, s2 = 0; i <= n; ++i) {
B[i] = sub(mul(i, s1), s2);
s1 = add(s1, c[i]), s2 = add(s2, mul(i, c[i]));
}
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; j += i)
ans[j] = add(ans[j], mul(A[i], B[j / i]));
for (int i = 1; i <= n; ++i)
std::cout << ans[i] << " \n"[i == n];
}