結果

問題 No.2891 Mint
ユーザー ooaiu
提出日時 2024-12-16 10:38:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 3,554 ms
コンパイル使用メモリ 253,424 KB
実行使用メモリ 200,272 KB
最終ジャッジ日時 2024-12-16 10:39:04
合計ジャッジ時間 16,909 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 25 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef LOCAL
#include <bits/stdc++.h>

using namespace std;

#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif

vector<array<int64_t, 3>> Quotients(int64_t P) {
    vector<array<int64_t, 3>> res;
    int64_t l = 1;
    while (l <= P) {
        int64_t p = P / l;
        int64_t r = P / p + 1;
        res.push_back({p, l, r});
        l = r;
    }
    return res;
}
#include <atcoder/modint>
using mint = atcoder::modint998244353;
int64_t arith(int64_t a0, int64_t d, int64_t len) { return (a0 * 2 + (len - 1) * d) * len / 2; }
void solve() {
    int64_t N, M;
    cin >> N >> M;
    vector<array<int64_t, 3>> qq = Quotients(M);
    vector<int64_t> thr;
    vector<int64_t> pref{0};
    for (const auto& [p, l, r] : qq) {
        thr.push_back(l);
        pref.push_back(pref.back() + arith(M % l, -p, r - l));
    }
    const auto g = [&](int r) -> int64_t {
        if(r <= 0) return 0;
        int hi = r, lo = 0;
        while (hi > lo + 1) {
            int mi = (hi + lo) / 2;
            (M / mi == M / r ? hi : lo) = mi;
        }
        int k = distance(thr.begin(), lower_bound(thr.begin(), thr.end(), hi));
        mint ans = pref[k];
        ans += arith(M % hi, -M / hi, r - hi + 1);
        return ans.val();
    };
    cout << g(N) << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int tt = 1;
    // std::cin >> tt;
    while (tt--) {
        solve();
    }
}
0