結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-03-28 19:20:49
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 117 ms / 1,000 ms
コード長 1,706 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 107,296 KB
実行使用メモリ 14,184 KB
最終ジャッジ日時 2023-09-04 06:48:08
合計ジャッジ時間 6,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
13,980 KB
testcase_01 AC 110 ms
13,716 KB
testcase_02 AC 109 ms
13,420 KB
testcase_03 AC 116 ms
12,964 KB
testcase_04 AC 105 ms
13,516 KB
testcase_05 AC 108 ms
13,040 KB
testcase_06 AC 108 ms
13,496 KB
testcase_07 AC 117 ms
14,184 KB
testcase_08 AC 113 ms
13,640 KB
testcase_09 AC 115 ms
12,820 KB
testcase_10 AC 112 ms
13,432 KB
testcase_11 AC 113 ms
13,576 KB
testcase_12 AC 115 ms
12,840 KB
testcase_13 AC 109 ms
13,376 KB
testcase_14 AC 106 ms
13,104 KB
testcase_15 AC 102 ms
13,420 KB
testcase_16 AC 107 ms
13,292 KB
testcase_17 AC 101 ms
13,140 KB
testcase_18 AC 103 ms
14,032 KB
testcase_19 AC 102 ms
13,956 KB
testcase_20 AC 110 ms
13,072 KB
testcase_21 AC 113 ms
13,056 KB
testcase_22 AC 113 ms
13,872 KB
testcase_23 AC 102 ms
13,672 KB
testcase_24 AC 100 ms
13,112 KB
testcase_25 AC 109 ms
13,280 KB
testcase_26 AC 96 ms
13,792 KB
testcase_27 AC 101 ms
13,972 KB
testcase_28 AC 102 ms
13,096 KB
testcase_29 AC 102 ms
12,980 KB
testcase_30 AC 99 ms
13,200 KB
testcase_31 AC 101 ms
12,864 KB
testcase_32 AC 104 ms
13,896 KB
testcase_33 AC 114 ms
13,452 KB
testcase_34 AC 117 ms
12,876 KB
testcase_35 AC 106 ms
13,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum LIM = 10^^7 + 10;

void main() {
  auto isnp = new bool[LIM];
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      for (int n = 2 * p; n < LIM; n += p) {
        isnp[n] = true;
      }
    }
  }
  
  try {
    for (; ; ) {
      const N = readInt();
      const L = readInt();
      
      long ans;
      foreach (p; 2 .. LIM) {
        if (L < (N - 1) * p) {
          break;
        }
        if (!isnp[p]) {
          ans += L - (N - 1) * p + 1;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0