結果

問題 No.752 mod数列
ユーザー PachicobuePachicobue
提出日時 2018-11-10 00:21:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 197,232 KB
実行使用メモリ 81,720 KB
最終ジャッジ日時 2023-08-13 12:37:11
合計ジャッジ時間 11,946 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
81,500 KB
testcase_01 AC 122 ms
81,560 KB
testcase_02 AC 122 ms
81,480 KB
testcase_03 AC 123 ms
81,496 KB
testcase_04 AC 123 ms
81,572 KB
testcase_05 AC 124 ms
81,444 KB
testcase_06 AC 123 ms
81,632 KB
testcase_07 AC 122 ms
81,492 KB
testcase_08 AC 122 ms
81,448 KB
testcase_09 AC 123 ms
81,448 KB
testcase_10 AC 127 ms
81,452 KB
testcase_11 AC 125 ms
81,516 KB
testcase_12 AC 125 ms
81,512 KB
testcase_13 AC 125 ms
81,440 KB
testcase_14 AC 125 ms
81,700 KB
testcase_15 AC 267 ms
81,580 KB
testcase_16 AC 271 ms
81,440 KB
testcase_17 AC 406 ms
81,596 KB
testcase_18 AC 280 ms
81,512 KB
testcase_19 AC 274 ms
81,716 KB
testcase_20 AC 295 ms
81,460 KB
testcase_21 AC 292 ms
81,516 KB
testcase_22 AC 308 ms
81,440 KB
testcase_23 AC 292 ms
81,460 KB
testcase_24 AC 291 ms
81,512 KB
testcase_25 AC 224 ms
81,720 KB
testcase_26 AC 344 ms
81,444 KB
testcase_27 AC 266 ms
81,520 KB
testcase_28 AC 318 ms
81,448 KB
testcase_29 AC 326 ms
81,440 KB
testcase_30 AC 405 ms
81,448 KB
testcase_31 AC 122 ms
81,576 KB
testcase_32 AC 122 ms
81,472 KB
testcase_33 AC 122 ms
81,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//=================================
// Created on: 2018/11/09 21:30:39
//=================================
#include <bits/stdc++.h>
using ll = long long;
constexpr ll MAX = 10000000;
constexpr int NUM = 100;
ll small[MAX + 1], start[NUM + 1], end[NUM + 1];
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; 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; 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) << std::endl;
    }
    return 0;
}
0