結果

問題 No.752 mod数列
ユーザー treeonetreeone
提出日時 2018-11-09 23:56:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 443 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 207,784 KB
実行使用メモリ 21,076 KB
最終ジャッジ日時 2023-08-13 12:16:44
合計ジャッジ時間 9,948 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 21 ms
9,752 KB
testcase_11 AC 12 ms
6,316 KB
testcase_12 AC 18 ms
8,508 KB
testcase_13 AC 15 ms
7,408 KB
testcase_14 AC 22 ms
9,828 KB
testcase_15 AC 199 ms
4,376 KB
testcase_16 AC 287 ms
6,252 KB
testcase_17 AC 414 ms
18,396 KB
testcase_18 AC 289 ms
8,468 KB
testcase_19 AC 324 ms
10,228 KB
testcase_20 AC 413 ms
16,328 KB
testcase_21 AC 399 ms
16,140 KB
testcase_22 AC 404 ms
15,824 KB
testcase_23 AC 423 ms
16,616 KB
testcase_24 AC 418 ms
16,392 KB
testcase_25 AC 142 ms
14,592 KB
testcase_26 AC 354 ms
18,248 KB
testcase_27 AC 247 ms
15,016 KB
testcase_28 AC 325 ms
17,424 KB
testcase_29 AC 345 ms
14,280 KB
testcase_30 AC 475 ms
21,076 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 14 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
using namespace std;
int p, q;
map<int, int> dp;

int calc(int n){
    if(dp.count(n)) return dp[n];
    int q = p / n;
    int x = p / (q + 1) + 1;
    return dp[n] = (p % n + p % x) * (n - x + 1) / 2 + calc(x - 1);
}

signed main(){
    cin >> p >> q;
    dp[0] = 0;
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << calc(r) - calc(l - 1) << endl;
    }
}
0