結果

問題 No.732 3PrimeCounting
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-04-05 17:19:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 806 ms / 3,000 ms
コード長 1,943 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 154,248 KB
実行使用メモリ 8,440 KB
最終ジャッジ日時 2023-09-04 00:22:54
合計ジャッジ時間 12,933 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,412 KB
testcase_01 AC 7 ms
7,240 KB
testcase_02 AC 6 ms
6,976 KB
testcase_03 AC 7 ms
8,188 KB
testcase_04 AC 6 ms
6,872 KB
testcase_05 AC 6 ms
7,460 KB
testcase_06 AC 7 ms
6,932 KB
testcase_07 AC 6 ms
7,152 KB
testcase_08 AC 7 ms
6,924 KB
testcase_09 AC 7 ms
7,444 KB
testcase_10 AC 6 ms
7,684 KB
testcase_11 AC 7 ms
6,712 KB
testcase_12 AC 6 ms
7,448 KB
testcase_13 AC 7 ms
7,448 KB
testcase_14 AC 7 ms
7,448 KB
testcase_15 AC 6 ms
6,924 KB
testcase_16 AC 7 ms
7,196 KB
testcase_17 AC 6 ms
6,932 KB
testcase_18 AC 7 ms
7,180 KB
testcase_19 AC 6 ms
6,660 KB
testcase_20 AC 7 ms
7,464 KB
testcase_21 AC 8 ms
8,440 KB
testcase_22 AC 7 ms
6,920 KB
testcase_23 AC 7 ms
6,608 KB
testcase_24 AC 6 ms
6,864 KB
testcase_25 AC 9 ms
7,448 KB
testcase_26 AC 8 ms
7,176 KB
testcase_27 AC 6 ms
8,148 KB
testcase_28 AC 7 ms
6,924 KB
testcase_29 AC 7 ms
8,120 KB
testcase_30 AC 7 ms
6,972 KB
testcase_31 AC 7 ms
7,244 KB
testcase_32 AC 8 ms
8,176 KB
testcase_33 AC 8 ms
7,656 KB
testcase_34 AC 8 ms
6,872 KB
testcase_35 AC 7 ms
6,608 KB
testcase_36 AC 7 ms
7,184 KB
testcase_37 AC 6 ms
7,916 KB
testcase_38 AC 6 ms
6,932 KB
testcase_39 AC 7 ms
7,180 KB
testcase_40 AC 8 ms
7,400 KB
testcase_41 AC 8 ms
7,184 KB
testcase_42 AC 7 ms
7,876 KB
testcase_43 AC 7 ms
6,912 KB
testcase_44 AC 7 ms
6,924 KB
testcase_45 AC 7 ms
6,920 KB
testcase_46 AC 6 ms
6,620 KB
testcase_47 AC 6 ms
7,912 KB
testcase_48 AC 10 ms
7,404 KB
testcase_49 AC 9 ms
7,416 KB
testcase_50 AC 7 ms
6,872 KB
testcase_51 AC 7 ms
7,132 KB
testcase_52 AC 6 ms
6,616 KB
testcase_53 AC 17 ms
6,928 KB
testcase_54 AC 230 ms
6,720 KB
testcase_55 AC 242 ms
6,868 KB
testcase_56 AC 233 ms
8,120 KB
testcase_57 AC 43 ms
7,152 KB
testcase_58 AC 42 ms
6,876 KB
testcase_59 AC 18 ms
8,280 KB
testcase_60 AC 63 ms
7,844 KB
testcase_61 AC 63 ms
7,236 KB
testcase_62 AC 313 ms
7,668 KB
testcase_63 AC 121 ms
7,180 KB
testcase_64 AC 83 ms
7,200 KB
testcase_65 AC 81 ms
7,604 KB
testcase_66 AC 6 ms
7,916 KB
testcase_67 AC 6 ms
6,868 KB
testcase_68 AC 271 ms
6,864 KB
testcase_69 AC 272 ms
7,136 KB
testcase_70 AC 232 ms
7,908 KB
testcase_71 AC 237 ms
6,864 KB
testcase_72 AC 113 ms
6,608 KB
testcase_73 AC 577 ms
6,600 KB
testcase_74 AC 559 ms
7,448 KB
testcase_75 AC 9 ms
7,192 KB
testcase_76 AC 258 ms
7,444 KB
testcase_77 AC 46 ms
6,660 KB
testcase_78 AC 417 ms
7,516 KB
testcase_79 AC 276 ms
7,116 KB
testcase_80 AC 367 ms
7,188 KB
testcase_81 AC 239 ms
7,452 KB
testcase_82 AC 7 ms
7,184 KB
testcase_83 AC 44 ms
7,660 KB
testcase_84 AC 50 ms
7,244 KB
testcase_85 AC 193 ms
7,856 KB
testcase_86 AC 369 ms
7,852 KB
testcase_87 AC 806 ms
7,180 KB
testcase_88 AC 803 ms
7,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, 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 = 4 * 10^^5;

int N;

void main() {
  auto isnp = new bool[LIM];
  int[] primes;
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      primes ~= p;
      for (int n = 2 * p; n < LIM; n += p) {
        isnp[n] = true;
      }
    }
  }
  stderr.writeln(primes.length);
  stderr.writeln(primes[0 .. 10]);
  stderr.writeln(primes[$ - 10 .. $]);
  
  try {
    for (; ; ) {
      N = readInt();
      
      long ans;
      auto cnt = new long[LIM];
      foreach (ib, b; primes) {
        if (b > N) {
          break;
        }
        foreach (d; primes[ib .. $]) {
          if (d - b > N + N) {
            break;
          }
          ans += cnt[d - b];
        }
        foreach (a; primes[0 .. ib]) {
          ++cnt[a + b];
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0