結果

問題 No.752 mod数列
ユーザー poyompoypoyompoy
提出日時 2018-11-09 22:02:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,199 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 80,064 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 04:50:17
合計ジャッジ時間 4,854 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 172 ms
6,944 KB
testcase_16 AC 177 ms
6,944 KB
testcase_17 AC 185 ms
6,944 KB
testcase_18 AC 167 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 157 ms
6,940 KB
testcase_21 AC 155 ms
6,940 KB
testcase_22 AC 157 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 156 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 WA -
testcase_33 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

struct P {
  long long l;
  long long r;
  long long sum;
  P(long long l_, long long r_, long long sum_) : l(l_), r(r_), sum(sum_) {}
};

bool operator<(P a, P b) {
  return a.l < b.l;
}

long long S(long long l, long long r) {
  return r * (r + 1) / 2 - l * (l + 1) / 2;
}

vector<P> kinoe(long long n) {
  vector<P> res;
  int i;
  for (i = 1; i * i <= n; i++) {
    res.emplace_back(n / (i + 1) + 1, n / i + 1, i * S(n / (i + 1), n / i));
  }
  for (long long j = 1; j <= n / i; j++) {
    res.emplace_back(j, j + 1, (n / j) * j);
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  long long p;
  int q;
  cin >> p >> q;
  auto ps = kinoe(p);
  vector<long long> sum(ps.size() + 1);
  for (int i = 0; i < ps.size(); i++) {
    sum[i + 1] = sum[i] + ps[i].sum;
  }
  auto f = [&](long long x) {
    if (x == 0) return 0LL;
    int k = (upper_bound(ps.begin(), ps.end(), P(x, 0, 0)) - ps.begin()) - 1;
    long long res = p*x - sum[k];
    res -= (p / x) * S(ps[k].l - 1, x);
    return res;
  };
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    cout << f(r) - f(l - 1) << endl;
  }
}
0