結果

問題 No.752 mod数列
ユーザー PachicobuePachicobue
提出日時 2018-11-11 02:08:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 200,308 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2024-05-05 10:24:32
合計ジャッジ時間 10,626 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
81,608 KB
testcase_01 AC 121 ms
81,416 KB
testcase_02 AC 121 ms
81,632 KB
testcase_03 AC 122 ms
81,500 KB
testcase_04 AC 121 ms
81,560 KB
testcase_05 AC 121 ms
81,616 KB
testcase_06 AC 122 ms
81,536 KB
testcase_07 AC 122 ms
81,424 KB
testcase_08 AC 123 ms
81,652 KB
testcase_09 AC 122 ms
81,432 KB
testcase_10 AC 124 ms
81,536 KB
testcase_11 AC 122 ms
81,664 KB
testcase_12 AC 123 ms
81,616 KB
testcase_13 AC 125 ms
81,536 KB
testcase_14 AC 124 ms
81,480 KB
testcase_15 AC 143 ms
81,536 KB
testcase_16 AC 147 ms
81,664 KB
testcase_17 AC 285 ms
81,504 KB
testcase_18 AC 151 ms
81,440 KB
testcase_19 AC 151 ms
81,524 KB
testcase_20 AC 161 ms
81,596 KB
testcase_21 AC 164 ms
81,528 KB
testcase_22 AC 160 ms
81,424 KB
testcase_23 AC 162 ms
81,536 KB
testcase_24 AC 161 ms
81,652 KB
testcase_25 AC 187 ms
81,476 KB
testcase_26 AC 239 ms
81,640 KB
testcase_27 AC 191 ms
81,476 KB
testcase_28 AC 229 ms
81,664 KB
testcase_29 AC 200 ms
81,608 KB
testcase_30 AC 272 ms
81,536 KB
testcase_31 AC 122 ms
81,436 KB
testcase_32 AC 122 ms
81,540 KB
testcase_33 AC 122 ms
81,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
constexpr ll MAX = 10000000;
constexpr int NUM = 100;
ll small[MAX + 1], start[NUM], end[NUM];
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    ll P;
    int Q;
    std::cin >> P >> Q;
    for (ll i = 1; i <= MAX; i++) { small[i] = small[i - 1] + (P % i); }
    for (ll i = NUM - 1; i >= 1; i--) { start[i] = P / (i + 1) + 1, end[i] = P / i; }
    auto get = [&](ll ind) {
        ll ans = 0;
        if (ind > P) { ans += (ind - P) * P, ind = P; }
        if (ind <= MAX) { return ans + small[ind]; }
        ans += small[MAX];
        for (int i = NUM - 1; i >= 1 and start[i] <= ind; i--) {
            const ll S = std::max(MAX + 1, start[i]), T = std::min(end[i], ind);
            if (S > T) { continue; }
            ans += (2 * P - (P / S) * (S + T)) * (T - S + 1) / 2;
        }
        return ans;
    };
    for (int q = 0; q < Q; q++) {
        ll L, R;
        std::cin >> L >> R;
        std::cout << get(R) - get(L - 1) << "\n";
    }
    return 0;
}
0