結果

問題 No.752 mod数列
ユーザー 0w10w1
提出日時 2018-12-09 22:57:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 2,684 ms
コンパイル使用メモリ 209,644 KB
実行使用メモリ 20,060 KB
最終ジャッジ日時 2023-10-14 21:57:55
合計ジャッジ時間 9,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 19 ms
8,348 KB
testcase_11 AC 10 ms
5,644 KB
testcase_12 AC 17 ms
7,532 KB
testcase_13 AC 13 ms
6,552 KB
testcase_14 AC 19 ms
8,512 KB
testcase_15 AC 168 ms
4,348 KB
testcase_16 AC 251 ms
5,944 KB
testcase_17 AC 357 ms
16,380 KB
testcase_18 AC 251 ms
8,348 KB
testcase_19 AC 284 ms
10,296 KB
testcase_20 AC 353 ms
16,196 KB
testcase_21 AC 348 ms
16,120 KB
testcase_22 AC 358 ms
15,772 KB
testcase_23 AC 365 ms
16,500 KB
testcase_24 AC 357 ms
16,164 KB
testcase_25 AC 126 ms
12,900 KB
testcase_26 AC 299 ms
16,672 KB
testcase_27 AC 212 ms
13,512 KB
testcase_28 AC 280 ms
15,776 KB
testcase_29 AC 293 ms
13,448 KB
testcase_30 AC 397 ms
20,060 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,356 KB
testcase_33 AC 12 ms
7,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);

  int P, Q;
  cin >> P >> Q;

  map<int, int64_t> dp;
  dp[0] = 0;
  function<int64_t(int)> solve = [&](int u) {
    if (dp.count(u)) return dp[u];
    int k = P / u;
    int l = P / (k + 1);
    return dp[u] = solve(l) + 1LL * (P % u + P % (l + 1)) * (u - l) / 2;
  };

  for (int i = 0; i < Q; ++i) {
    int L, R;
    cin >> L >> R;
    cout << solve(R) - solve(L - 1) << endl;
  }

  return 0;
}
0