結果

問題 No.3505 Sum of Prod of Root
コンテスト
ユーザー jupiter_68
提出日時 2026-04-18 07:31:23
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 3,648 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,698 ms
コンパイル使用メモリ 228,548 KB
実行使用メモリ 1,308,384 KB
最終ジャッジ日時 2026-04-18 07:31:45
合計ジャッジ時間 5,942 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other WA * 3 MLE * 2 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for(ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for(ll i = (r)-1; i >= (l); --i)
#define sz(x) (ll) (x).size()
template <typename T>
bool chmax(T &a, const T& b) { return a < b ? a = b, true : false; }
template <typename T>
bool chmin(T &a, const T& b) { return a > b ? a = b, true : false; }

const ll mod = 998244353; // 1000000007;

struct mint {
    ll x;
    mint(ll y = 0) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    mint &operator+=(const mint &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint &p) {
        x = (ll)(1ll * x * p.x % mod);
        return *this;
    }
    mint &operator/=(const mint &p) {
        *this *= p.inv();
        return *this;
    }
    mint operator-() const { return mint(-x); }
    mint operator+(const mint &p) const { return mint(*this) += p; }
    mint operator-(const mint &p) const { return mint(*this) -= p; }
    mint operator*(const mint &p) const { return mint(*this) *= p; }
    mint operator/(const mint &p) const { return mint(*this) /= p; }
    bool operator==(const mint &p) const { return x == p.x; }
    bool operator!=(const mint &p) const { return x != p.x; }
    friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
    friend istream &operator>>(istream &is, mint &a) {
        ll t; is >> t; a = mint(t); return (is);
    }
    mint inv() const { return pow(mod - 2); }
    mint pow(ll n) const {
        mint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
};

vl compress(vl& v){
    ll N = sz(v);
    vl re = v;
    sort(all(re));
    re.erase(unique(all(re)), re.end());
    rep(i, N){
        ll ix = lower_bound(all(re), v[i]) - re.begin();
        v[i] = ix;
    }
    return re;
}

void solve(){
    ll N; cin >> N;
    auto isqrt = [&](ll n)->ll{
        ll x = sqrt(n);
        while((x+1) * (x+1) <= n) x++;
        while(x * x > n) x--;
        return x;
    };
    auto f = [&](ll n)->mint{
        mint re = n * (n+1) / 2;
        ll s = isqrt(n);
        re *= s;
        mint dec = (s-1) * s;
        dec *= s+1;
        dec *= s+2;
        dec *= 2*s+1;
        dec /= 20;
        re -= dec;
        return re;
    };
    vl v;
    unordered_map<ll,mint> mp;
    reps(t, 2, 1000000){
        ll x = t * t * t;
        ll u = 3;
        while(x <= N){
            v.push_back(x);
            if(mp[x] == 0) mp[x] = 1;
            mp[x] *= t;
            x *= t;
        }
    }
    vec<pair<ll, mint>> V = {{1, 1}};
    for(auto p : mp) V.push_back(p);
    ll M = sz(V);
    rep(i, M-1){
        V[i+1].second *= V[i].second;
    }
    mint ans = 0;
    rep(i, M-1){
        ans += (f(V[i+1].first-1) - f(V[i].first-1)) * V[i].second;
    }
    ans += (f(N) - f(V[M-1].first-1)) * V[M-1].second;
    cout << ans << endl;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
0