結果
問題 | No.2891 Mint |
ユーザー |
![]() |
提出日時 | 2024-10-02 15:45:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 1,203 bytes |
コンパイル時間 | 1,870 ms |
コンパイル使用メモリ | 196,680 KB |
最終ジャッジ日時 | 2025-02-24 14:29:13 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
#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)ki<=sqrt(M)については愚直にやる(M/k>=sqrt(M))i>sqrt(M)ではM/k<sqrt(M)1<=j<=sqrt(M)-1に対して、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<=min(K, N); i++){if (M/i <= K) continue;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;}