結果

問題 No.752 mod数列
ユーザー ei1333333ei1333333
提出日時 2018-11-09 22:39:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 928 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 203,108 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-08-13 11:55:56
合計ジャッジ時間 8,671 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,768 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 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,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 325 ms
4,380 KB
testcase_11 AC 146 ms
4,380 KB
testcase_12 AC 265 ms
4,380 KB
testcase_13 AC 208 ms
4,380 KB
testcase_14 AC 328 ms
4,380 KB
testcase_15 AC 273 ms
4,376 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 <bits/stdc++.h>

using namespace std;

using int64 = long long;


int main() {
  int P, Q;
  cin >> P >> Q;

  vector< pair< pair< int, int >, int > > rad;
  int ptr = 1;
  while(ptr <= P) {
    int ok = ptr, ng = P + 1;
    int real = P / ptr;
    while(ng - ok > 1) {
      int mid = (ok + ng) / 2;
      if(P / mid == real) ok = mid;
      else ng = mid;
    }
    rad.emplace_back(make_pair(ptr, ok), P / ptr);
    ptr = ok + 1;
  }


  auto get = [&](int L) {
    __int128_t add = 1LL * P * L;
    for(auto &p : rad) {
      auto range = p.first;
      auto val = p.second;

      int latte = range.first;
      int malta = min(range.second, L);
      if(latte > malta) break;
      add += val * (1LL * latte * (latte - 1) / 2);
      add -= val * (1LL * malta * (malta + 1) / 2);
    }
    return (int64) add;
  };

  while(Q--) {
    int L, R;
    cin >> L >> R;
    cout << get(R) - get(L - 1) << endl;
  }

}

0