結果

問題 No.752 mod数列
ユーザー PachicobuePachicobue
提出日時 2018-11-10 00:06:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,177 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 199,232 KB
実行使用メモリ 81,676 KB
最終ジャッジ日時 2023-08-13 12:18:51
合計ジャッジ時間 11,904 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
81,460 KB
testcase_01 AC 121 ms
81,664 KB
testcase_02 AC 121 ms
81,444 KB
testcase_03 AC 121 ms
81,540 KB
testcase_04 AC 122 ms
81,452 KB
testcase_05 AC 122 ms
81,676 KB
testcase_06 AC 121 ms
81,404 KB
testcase_07 AC 121 ms
81,504 KB
testcase_08 AC 121 ms
81,544 KB
testcase_09 AC 121 ms
81,460 KB
testcase_10 AC 124 ms
81,480 KB
testcase_11 AC 124 ms
81,492 KB
testcase_12 AC 124 ms
81,472 KB
testcase_13 AC 124 ms
81,456 KB
testcase_14 AC 124 ms
81,492 KB
testcase_15 AC 268 ms
81,436 KB
testcase_16 AC 272 ms
81,452 KB
testcase_17 AC 405 ms
81,408 KB
testcase_18 AC 277 ms
81,568 KB
testcase_19 WA -
testcase_20 AC 291 ms
81,488 KB
testcase_21 AC 289 ms
81,624 KB
testcase_22 AC 291 ms
81,492 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 225 ms
81,404 KB
testcase_26 AC 345 ms
81,556 KB
testcase_27 AC 263 ms
81,504 KB
testcase_28 AC 322 ms
81,404 KB
testcase_29 AC 328 ms
81,548 KB
testcase_30 AC 405 ms
81,484 KB
testcase_31 AC 121 ms
81,480 KB
testcase_32 AC 121 ms
81,492 KB
testcase_33 AC 121 ms
81,536 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], 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) {
        if (ind <= MAX) { return small[ind]; }
        ll ans = small[MAX];
        if (ind > P) { ans += (ind - P) * P, ind = P; }
        for (int i = NUM - 1; i >= 1 and start[i] <= ind; i--) {
            if (start[i] > end[i]) { continue; }
            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