結果

問題 No.3505 Sum of Prod of Root
コンテスト
ユーザー こめだわら
提出日時 2026-04-21 10:41:07
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,927 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,387 ms
コンパイル使用メモリ 382,036 KB
実行使用メモリ 20,084 KB
最終ジャッジ日時 2026-04-21 10:41:26
合計ジャッジ時間 11,320 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define rep(i,n) for(ll i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
    if (a.empty()) return os;
    os << a.front();
    for (auto e : a | views::drop(1)){
        os << ' ' << e;
    }
    return os;
}

void dump(auto ...vs){
    ((cout << vs << ' '), ...) << endl;
}

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;

ll isqrt(ll n){
    assert(n>=0);
    ll s=sqrtl(n);
    while ((s+1)*(s+1)<=n)s++;
    while (s*s>n)s--;
    return s;
}

const ll INF=4e18;

void solve() {
    vector<mint> sum_sqrt_cff={0,6,75,150,105,24};
    rep(i,6){
        sum_sqrt_cff[i]/=60;
    }
    ll N;
    cin>>N;
    auto sum_sqrt_2=[&](ll n)->mint {
        ll x=1;
        mint res=0;
        rep(i,6){
            res+=sum_sqrt_cff[i]*x;
            x*=n;
        }
        return res;
    };
    auto sum_sqrt=[&](ll n)->mint {
        ll sn=isqrt(n);
        mint res=sum_sqrt_2(sn-1);
        ll l=sn*sn;
        mint t=(n-l)*(n-1+l)/2;
        t*=sn;
        res+=t;
        return res;
    };
    vector<ll> P;
    P.push_back(1);
    for (ll a=2;a<=1000010;a++){
        ll p=a*a;
        for (ll d=3;d<62;d++){
            if (p>INF/a)break;
            p*=a;
            P.push_back(p);
        }
    }
    sort(all(P));
    P.erase(unique(all(P)),P.end());
    ll S=P.size();
    mint ans=0;
    vector<ll> now(61,1);
    rep(i,S-1){
        ll l=P[i];
        ll r=P[i+1];
        for (ll a=3;a<61;a++){
            if (intpow(now[a]+1,a)==l)now[a]++;
        }
        // dump(l);
        // dump(now);
        if (r>N){
            mint t=sum_sqrt(N+1)-sum_sqrt(l);
            for (ll a=3;a<61;a++){
                if (now[a]==1)break;
                t*=now[a];
            }
            ans+=t;
            break;
        }
        else{
            mint t=sum_sqrt(r)-sum_sqrt(l);
            for (ll a=3;a<61;a++){
                if (now[a]==1)break;
                t*=now[a];
            }
            ans+=t;
        }
    }
    cout<<ans.val()<<'\n';
    return;
}


int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T=1;
    while (T--){
        solve();
    }
    return 0;
}
0