結果
| 問題 | No.3505 Sum of Prod of Root |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2026-04-18 04:43:32 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,962 bytes |
| 記録 | |
| コンパイル時間 | 1,556 ms |
| コンパイル使用メモリ | 192,796 KB |
| 実行使用メモリ | 27,884 KB |
| 最終ジャッジ日時 | 2026-04-18 04:43:35 |
| 合計ジャッジ時間 | 2,790 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 WA * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long isqrt(long long x)
{
long long res = sqrt(x);
while ((res + 1) * (res + 1) <= x) ++res;
while (res * res > x) --res;
return res;
}
int main()
{
const long long inf1 = 1000000000000000000LL, inf2 = 1000000000000000001LL;
const int mod = 998244353, b = 1e6;
vector<long long> inv(b + 1);
inv[1] = 1;
for (int i = 2; i <= b; ++i) inv[i] = mod - (mod / i) * inv[mod % i] % mod;
long long n;
cin >> n;
auto cal = [&](long long x) -> long long
{
long long iq = isqrt(x) - 1;
iq %= mod;
long long ret = inv[20] * iq % mod * (iq + 1) % mod * (iq + 2) % mod * (8LL * iq % mod * iq % mod + 11 * iq % mod + 1) % mod;
long long ls = x % mod * (x % mod + 1) % mod * inv[2] % mod;
long long lv = (iq + 1) * (iq + 1) % mod;
ls -= lv * (lv - 1 + mod) % mod * inv[2] % mod;
ls = (ls % mod + mod) % mod;
ls = ls * (iq + 1) % mod;
ret = (ret + ls) % mod;
return ret;
};
auto pow = [&](long long a, int k) -> long long
{
long long ret = 1;
while (k--)
{
if (ret >= (n + 1) / a) return n + 1;
ret *= a;
}
return ret;
};
vector<pair<long long, int>> all;
for (int i = 3; i <= 60; ++i)
{
for (int j = 2; j <= b; ++j)
{
long long tmp = pow(j, i);
if (tmp > n) break;
all.push_back({tmp, j});
}
}
sort(all.begin(), all.end());
long long bs = 1, ans = 0, now = 0;
int siz = all.size();
for (int l = 0, r = 0; l < siz; l = r)
{
long long tmp = (cal(all[l].first - 1) - cal(now) + mod) % mod;
ans = (ans + bs * tmp % mod) % mod;
while (r < siz && all[r].first == all[l].first)
{
bs = bs * inv[all[r].second - 1] % mod * all[r].second % mod;
++r;
}
now = all[l].first - 1;
}
long long tmp = (cal(n) - cal(now) + mod) % mod;
ans = (ans + bs * tmp % mod) % mod;
cout << ans << endl;
}
テナガザル