Function!
fa(x)=ax(a>0,a≠1)f_a(x) = a ^ x(a > 0, \ a \neq 1)fa(x)=ax(a>0, a=1),我们要求∑a=2n(a∑b=an⌊fa−1(b)⌋⌈fb−1(a)⌉)\sum\limits_{a = 2} ^{n} \left(a \sum\limits_{b = a} ^{n} \lfloor f_a ^{-1}(b) \rfloor \lceil f_b ^{-1}(a) \rceil \right)a=2∑n(ab=a∑n⌊fa−1(b)⌋⌈fb−1(a)⌉)。
∑a=2n(a∑b=an⌊fa−1(b)⌋⌈fb−1(a)⌉)∑a=2n(a∑b=an⌊logab⌋⌈logba⌉)b≥a,则有⌈logba⌉=1∑a=2n(a∑b=an⌊logab⌋)\sum\limits_{a = 2} ^{n} \left(a \sum\limits_{b = a} ^{n} \lfloor f_a ^{-1}(b) \rfloor \lceil f_b ^{-1}(a) \rceil \right)\\ \sum_{a = 2} ^{n} \left( a \sum_{b = a} ^{n} \lfloor \log_a b \rfloor \lceil \log_b a \rceil \right)\\ b \geq a,则有 \lceil \log _b a \rceil = 1\\ \sum_{a = 2} ^{n} \left( a \sum_{b = a} ^{n} \lfloor \log_a b \rfloor\right)\\ a=2∑n(ab=a∑n⌊fa−1(b)⌋⌈fb−1(a)⌉)a=2∑n(ab=a∑n⌊logab⌋⌈logba⌉)b≥a,则有⌈logba⌉=1a=2∑n(ab=a∑n⌊logab⌋)
且容易发现,当a×a>na \times a > na×a>n时,有⌊logab⌋\lfloor \log _a b \rfloor⌊logab⌋恒为111,所以可以单独用公式计算。
#include <bits/stdc++.h>using namespace std;const int mod = 998244353, inv2 = mod + 1 >> 1, inv6 = (mod + 1) / 6;typedef long long ll;ll calc1(ll l, ll r) {return (l + r) % mod * ((r - l + 1) % mod) % mod * inv2 % mod;
}ll calc2(ll n) {n %= mod;return n * (n + 1) % mod * (2 * n + 1) % mod * inv6 % mod;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);ll a, n, ans = 0;cin >> n;for (a = 2; a * a <= n; a++) {for (ll l = a, r, k = 1; l <= n; l = r + 1, k++) {r = min(l * a - 1, n);int tot = (r - l + 1) % mod;ans = (ans + a * tot % mod * k % mod) % mod;}}// for (; a <= n; a++) {//原本我们是这样算的,当时这里可以变成,自然幂次求和的形式,所以可以快速算出来。// ans = (ans + a * (n - a + 1) % mod) % mod;// }ans = (ans + (n + 1) % mod * calc1(a, n) % mod) % mod;ans = ((ans - calc2(n) + calc2(a - 1)) % mod + mod) % mod;cout << ans << "\n";return 0;
}