結果

問題 No.752 mod数列
ユーザー te-shte-sh
提出日時 2018-11-16 12:25:21
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 92,128 KB
実行使用メモリ 5,620 KB
最終ジャッジ日時 2023-09-03 21:15:51
合計ジャッジ時間 4,205 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,500 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 64 ms
4,380 KB
testcase_16 AC 67 ms
4,376 KB
testcase_17 AC 77 ms
5,620 KB
testcase_18 AC 69 ms
4,376 KB
testcase_19 AC 74 ms
4,380 KB
testcase_20 AC 75 ms
4,376 KB
testcase_21 AC 75 ms
4,376 KB
testcase_22 AC 75 ms
4,380 KB
testcase_23 AC 77 ms
4,380 KB
testcase_24 AC 77 ms
4,376 KB
testcase_25 AC 25 ms
4,376 KB
testcase_26 AC 62 ms
4,400 KB
testcase_27 AC 45 ms
4,380 KB
testcase_28 AC 58 ms
4,380 KB
testcase_29 AC 72 ms
4,380 KB
testcase_30 AC 81 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long p; int q; readV(p, q);

  auto maxM = min(p, 10L^^4), maxK = p/(maxM+1);

  auto b = new long[](maxK+1);
  foreach (k; 1..maxK+1)
    b[k] = b[k-1] + p%k;

  auto c = new long[](maxM+2); c[$-1] = b[$-1];
  foreach_reverse (m; 1..maxM+1) {
    auto u = p/(m+1)+1, v = p/m;
    c[m] = c[m+1] + p*(v-u+1) - m*(v*(v+1)-u*(u-1))/2;
  }

  auto calc(long x)
  {
    if (x <= maxK) {
      return b[x];
    } else {
      auto m = p/x, u = p/(m+1)+1;
      return c[m+1] + p*(x-u+1) - m*(x*(x+1)-u*(u-1))/2;
    }
  }

  foreach (_; 0..q) {
    long l, r; readV(l, r);
    writeln(calc(r) - calc(l-1));
  }
}
0