結果

問題 No.752 mod数列
ユーザー ei1333333ei1333333
提出日時 2018-11-09 22:40:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 945 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 202,000 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-13 11:56:31
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,316 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 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,376 KB
testcase_10 AC 63 ms
4,380 KB
testcase_11 AC 29 ms
4,380 KB
testcase_12 AC 52 ms
4,376 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 64 ms
4,380 KB
testcase_15 AC 270 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 <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, int R) {
    __int128_t add = 1LL * P * (R - L + 1);
    for(auto &p : rad) {
      auto range = p.first;
      auto val = p.second;
      int latte = max(range.first, L);
      int malta = min(range.second, R);
      if(latte > malta) continue;
      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(L, R) << endl;
  }

}

0