結果

問題 No.752 mod数列
ユーザー PachicobuePachicobue
提出日時 2018-11-10 00:25:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 3,184 ms
コンパイル使用メモリ 213,260 KB
実行使用メモリ 81,672 KB
最終ジャッジ日時 2024-04-28 16:30:37
合計ジャッジ時間 12,873 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
81,672 KB
testcase_01 AC 151 ms
81,460 KB
testcase_02 AC 147 ms
81,452 KB
testcase_03 AC 147 ms
81,636 KB
testcase_04 AC 147 ms
81,620 KB
testcase_05 AC 147 ms
81,648 KB
testcase_06 AC 147 ms
81,624 KB
testcase_07 AC 147 ms
81,572 KB
testcase_08 AC 147 ms
81,516 KB
testcase_09 AC 147 ms
81,632 KB
testcase_10 AC 149 ms
81,504 KB
testcase_11 AC 148 ms
81,652 KB
testcase_12 AC 150 ms
81,440 KB
testcase_13 AC 148 ms
81,548 KB
testcase_14 AC 148 ms
81,504 KB
testcase_15 AC 173 ms
81,668 KB
testcase_16 AC 174 ms
81,592 KB
testcase_17 AC 302 ms
81,640 KB
testcase_18 AC 177 ms
81,492 KB
testcase_19 AC 175 ms
81,504 KB
testcase_20 AC 189 ms
81,636 KB
testcase_21 AC 188 ms
81,492 KB
testcase_22 AC 188 ms
81,596 KB
testcase_23 AC 190 ms
81,604 KB
testcase_24 AC 188 ms
81,556 KB
testcase_25 AC 216 ms
81,456 KB
testcase_26 AC 268 ms
81,664 KB
testcase_27 AC 216 ms
81,608 KB
testcase_28 AC 252 ms
81,580 KB
testcase_29 AC 225 ms
81,568 KB
testcase_30 AC 297 ms
81,560 KB
testcase_31 AC 148 ms
81,508 KB
testcase_32 AC 147 ms
81,616 KB
testcase_33 AC 148 ms
81,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#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