結果

問題 No.2891 Mint
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-09-14 11:10:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 5,412 ms
コンパイル使用メモリ 309,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-14 11:10:58
合計ジャッジ時間 8,099 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

using lint = long long;
using mint = atcoder::modint998244353;

int main() {
    lint n, m;
    cin >> n >> m;
    lint sq = sqrtl(m);
    mint ans = 0;
    for (lint i = 1; i <= min(sq, n); i++) {
        ans += mint(m % i);
    }
    auto calc = [](lint fst, lint lst, lint q) -> mint {
        lint cnt = (fst - lst) / q + 1;
        lint res = (fst + lst) * cnt / 2;
        return mint(res);
    };
    for (lint q = m / (sq + 1); q >= 1 && n > sq; q--) {
        if (q == m / n) {
            lint fst = m % (m / (q + 1) + 1);
            lint lst = m % n;
            ans += calc(fst, lst, q);
            break;
        } else {
            lint fst = m % (m / (q + 1) + 1);
            lint lst = m % q;
            ans += calc(fst, lst, q);
        }
    }
    ans += mint(max(0LL, n - m)) * mint(m);
    cout << ans.val() << endl;
}
0