結果

問題 No.752 mod数列
ユーザー poyompoypoyompoy
提出日時 2018-11-09 21:43:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 657 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 68,804 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-13 11:23:16
合計ジャッジ時間 13,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1,442 ms
4,380 KB
testcase_11 AC 644 ms
4,380 KB
testcase_12 AC 1,182 ms
4,384 KB
testcase_13 AC 915 ms
4,380 KB
testcase_14 AC 1,471 ms
4,380 KB
testcase_15 AC 1,751 ms
4,380 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

long long sum(long long l, long long r, long long k) {
  l = min(l, k);
  r = min(r, k);
  return r * (r + 1) / 2 - l * (l + 1) / 2;
}

long long kinoe(long long n, long long k) {
  long long res = 0;
  int i;
  for (i = 1; i * i <= n; i++) {
    res += i * sum(n / (i + 1), n / i, k);
  }
  for (long long j = 1; j <= min(n / i, k); j++) {
    res += (n / j) * j;
  }
  return res;
}

int main() {
  long long p;
  int q;
  cin >> p >> q;
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    cout << p * (r - l + 1) - (kinoe(p, r) - kinoe(p, l - 1)) << endl;
  }
}
0