結果

問題 No.752 mod数列
ユーザー merom686merom686
提出日時 2018-11-16 16:50:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,047 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 75,864 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 01:27:43
合計ジャッジ時間 4,159 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 22 ms
4,380 KB
testcase_16 AC 25 ms
4,380 KB
testcase_17 AC 34 ms
4,376 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 29 ms
4,376 KB
testcase_20 AC 33 ms
4,376 KB
testcase_21 AC 34 ms
4,376 KB
testcase_22 AC 33 ms
4,380 KB
testcase_23 AC 33 ms
4,380 KB
testcase_24 AC 34 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 26 ms
4,380 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 35 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int p, q;
    cin >> p >> q;

    auto g = [&](int l, int r) {
        int l1 = p % (l + 1);
        int r1 = p % r;
        return (ll)(l1 + r1) * (r - l) / 2;
    };

    int y = (int)sqrt(p);
    int x = p / y;
    vector<ll> s(x), t(y + 1);
    for (int i = 1; i < x; i++) {
        s[i] = s[i - 1] + p % i;
    }
    for (int i = 1; i <= y; i++) {
        t[i] = t[i - 1] + g(p / (i + 1), p / i);
    }

    auto f = [&](ll a) {
        if (a < x) return s[a];
        ll r = s[x - 1];
        if (p < a) {
            r += (a - p) * p;
            a = p;
        }
        int i = p / a;
        r += t[y] - t[i] + g(p / (i + 1), a);
        return r;
    };

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        cout << f(r) - f(l - 1) << '\n';
    }

    return 0;
}
0