結果
問題 | No.2891 Mint |
ユーザー |
![]() |
提出日時 | 2024-10-02 15:48:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,181 bytes |
コンパイル時間 | 2,396 ms |
コンパイル使用メモリ | 196,540 KB |
最終ジャッジ日時 | 2025-02-24 14:29:24 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 WA * 17 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>using namespace std;using ll = long long;using namespace atcoder;using mint = modint998244353;//calculate floor(sqrt(s))ll isqrt(ll s){ll l=0, r=3e9, c;while(r-l>1){c = (l+r)/2;if (c*c <= s) l = c;else r = c;}return l;}int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);/*sum(i=1, N)(M-(M/k)k)=MN-sum(i=1,N)(M/k)kM/iがsqrt(M-1)以下のiはO(sqrt(M))個しかないので愚直にやる。1<=j<=sqrt(M)に対して、M/k=jとなるkをまとめてj*(kの総和)j<=M/k<j+1M/(j+1)<k<=M/jL = floor(M/(j+1))+1R = max(floor(M/j), N)*/ll N, M, K, L, R;cin >> N >> M;mint ans=0, S, iv=mint(2).inv();K = isqrt(M);for (int i=1; i<=1e9; i++){if (M/i <= K) break;ans += (M/i)*i;}for (int j=K; j>=1; j--){L = M/(j+1)+1;R = min(M/j, N);if (L>R) continue;//L~Rの和S = mint(R)*(R+1)*iv-mint(L)*(L-1)*iv;ans += S*j;}cout << (mint(N)*M-ans).val() << endl;return 0;}