結果

問題 No.3505 Sum of Prod of Root
コンテスト
ユーザー n_bitand_n_per_3
提出日時 2026-12-01 01:03:34
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 2,000 ms
+ 845µs
コード長 2,173 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,735 ms
コンパイル使用メモリ 347,096 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-12-01 01:03:39
合計ジャッジ時間 4,845 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using i128 = __int128_t;
constexpr i64 MOD = 998244353;
constexpr i64 INV20 = (3 * MOD + 1) / 20;

inline i64 isqrt(i64 x) {
    i64 r = sqrt(double(x));
    if (r * r > x) --r;
    if ((r + 1) * (r + 1) <= x) ++r;
    return r;
}
// An integer congruent to 20 * sum_{i=1}^{x-1} i * floor(sqrt(i)).
inline i128 numerator(i64 x) {
    i64 r = isqrt(x);
    i64 z = uint64_t(x) % MOD;
    if (z > MOD / 2) z -= MOD;
    i64 u = uint64_t(r * r) % MOD;
    return i128(r) * (10 * z * (z - 1) - (u - 1) * (2 * u + 5 * r + 2));
}
inline i64 fourth(i64 x) { return x*x*x*x; }

// Stream fourth powers; store only powers with exponent >= 5.
i64 solve(i64 n) {
    vector<pair<i64, int>> events;
    int maxj = 1;
    for (int k = 5; (1LL << k) <= n; ++k) {
        for (i64 j = 2;; ++j) {
            i128 x = 1;
            for (int h = 0; h < k && x <= n; ++h) x *= j;
            if (x > n) break;
            events.emplace_back(i64(x), int(j));
            maxj = max(maxj, int(j));
        }
    }
    sort(events.begin(), events.end());
    events.emplace_back(n + 1, 0);
    vector<i64> inv(maxj + 1);
    inv[1] = 1;
    for (int j = 2; j <= maxj; ++j)
        inv[j] = MOD - MOD / j * inv[MOD % j] % MOD;

    i64 t = 2, k4 = 1, h = 1, weight = 1, ans = 0;
    i64 c = 8, x4 = 16;
    i128 prev = 0;
    size_t pos = 0;
    while (true) {
        i64 x = min(x4, events[pos].first);
        i128 acc = 0;
        for (; c < x; ++t, c = t*t*t) acc += numerator(c);
        i128 cur = (t - 1) * numerator(x);
        i64 delta = (cur - prev - acc) % MOD;
        ans = (ans + weight * delta) % MOD;
        prev = cur;
        if (x == n + 1) break;
        if (x == x4) {
            ++k4;
            x4 = fourth(k4 + 1);
        }
        while (events[pos].first == x) {
            int j = events[pos++].second;
            h = h * inv[j - 1] % MOD * j % MOD;
        }
        weight = h * k4 % MOD;
    }
    return (ans + MOD) % MOD * INV20 % MOD;
}
#ifndef BENCHMARK
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    i64 n; cin >> n;
    cout << solve(n) << '\n';
}
#endif
0