結果

問題 No.732 3PrimeCounting
ユーザー nebukuro09nebukuro09
提出日時 2018-09-07 23:07:32
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 652 ms / 3,000 ms
コード長 1,252 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 103,440 KB
実行使用メモリ 9,512 KB
最終ジャッジ日時 2023-09-03 20:56:55
合計ジャッジ時間 10,935 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 3 ms
4,500 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 3 ms
4,380 KB
testcase_49 AC 3 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 7 ms
4,376 KB
testcase_54 AC 167 ms
5,924 KB
testcase_55 AC 165 ms
5,944 KB
testcase_56 AC 164 ms
5,396 KB
testcase_57 AC 22 ms
4,804 KB
testcase_58 AC 22 ms
5,104 KB
testcase_59 AC 8 ms
4,376 KB
testcase_60 AC 33 ms
4,376 KB
testcase_61 AC 33 ms
4,376 KB
testcase_62 AC 247 ms
5,892 KB
testcase_63 AC 66 ms
4,892 KB
testcase_64 AC 44 ms
5,160 KB
testcase_65 AC 45 ms
4,380 KB
testcase_66 AC 1 ms
4,380 KB
testcase_67 AC 1 ms
4,376 KB
testcase_68 AC 195 ms
5,684 KB
testcase_69 AC 196 ms
5,620 KB
testcase_70 AC 161 ms
5,400 KB
testcase_71 AC 174 ms
5,680 KB
testcase_72 AC 66 ms
4,668 KB
testcase_73 AC 485 ms
9,512 KB
testcase_74 AC 467 ms
8,060 KB
testcase_75 AC 3 ms
4,380 KB
testcase_76 AC 186 ms
5,664 KB
testcase_77 AC 24 ms
4,872 KB
testcase_78 AC 325 ms
6,452 KB
testcase_79 AC 201 ms
5,680 KB
testcase_80 AC 286 ms
6,144 KB
testcase_81 AC 168 ms
5,400 KB
testcase_82 AC 2 ms
4,376 KB
testcase_83 AC 23 ms
4,380 KB
testcase_84 AC 26 ms
4,376 KB
testcase_85 AC 128 ms
5,880 KB
testcase_86 AC 289 ms
6,188 KB
testcase_87 AC 646 ms
8,708 KB
testcase_88 AC 652 ms
8,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;

    int[] P;
    auto is_P = new bool[](3*N+1);
    fill(is_P, true);
    is_P[0] = is_P[1] = false;

    foreach (i; 2..3*N+1) {
        if (!is_P[i]) continue;
        P ~= i;
        for (int j = i + i; j < 3*N+1; j += i) is_P[j] = false;
    }

    int M = P.length.to!int;
    auto P1 = P.filter!(p => p <= N && p % 3 == 1).array;
    auto P2 = P.filter!(p => p <= N && p % 3 == 2 && p != 2).array;
    auto A = new long[](3*N+1);
    auto B = new long[](3*N+1);
    foreach (i; 0..P1.length) foreach (j; i+1..P1.length) A[P1[i]+P1[j]] += 1;
    foreach (i; 0..P2.length) foreach (j; i+1..P2.length) B[P2[i]+P2[j]] += 1;

    long ans = 0;
    foreach (p; P) if (p >= 3) ans += A[p - 3] + B[p - 3];
    foreach (p1; P1) foreach (p; P) if (p - p1 > 0) ans += B[p - p1]; //, writeln(p, " ", p1, " ", B[p - p1]);
    foreach (p2; P2) foreach (p; P) if (p - p2 > 0) ans += A[p - p2]; //, writeln(p, " ", p2, " ", A[p - p2]);
    ans.writeln;
}
0