結果

問題 No.843 Triple Primes
ユーザー GrayCoderGrayCoder
提出日時 2019-06-29 20:07:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 16,848 KB
最終ジャッジ日時 2023-09-14 23:21:29
合計ジャッジ時間 3,450 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,976 KB
testcase_01 AC 52 ms
16,588 KB
testcase_02 AC 19 ms
9,176 KB
testcase_03 AC 19 ms
8,908 KB
testcase_04 AC 19 ms
9,148 KB
testcase_05 AC 19 ms
9,052 KB
testcase_06 AC 20 ms
9,076 KB
testcase_07 AC 46 ms
16,456 KB
testcase_08 AC 52 ms
16,500 KB
testcase_09 AC 53 ms
16,692 KB
testcase_10 AC 48 ms
16,516 KB
testcase_11 AC 51 ms
16,644 KB
testcase_12 AC 54 ms
16,716 KB
testcase_13 AC 53 ms
16,680 KB
testcase_14 AC 53 ms
16,552 KB
testcase_15 AC 49 ms
16,484 KB
testcase_16 AC 48 ms
16,292 KB
testcase_17 WA -
testcase_18 AC 19 ms
8,632 KB
testcase_19 AC 18 ms
9,064 KB
testcase_20 AC 29 ms
12,092 KB
testcase_21 AC 24 ms
10,308 KB
testcase_22 AC 42 ms
15,472 KB
testcase_23 AC 41 ms
15,160 KB
testcase_24 AC 30 ms
12,008 KB
testcase_25 AC 27 ms
10,716 KB
testcase_26 AC 55 ms
16,664 KB
testcase_27 AC 22 ms
9,700 KB
testcase_28 AC 53 ms
16,780 KB
testcase_29 AC 31 ms
12,024 KB
testcase_30 AC 55 ms
16,780 KB
testcase_31 AC 23 ms
9,668 KB
testcase_32 AC 21 ms
9,356 KB
testcase_33 AC 31 ms
12,004 KB
testcase_34 AC 39 ms
15,444 KB
testcase_35 AC 54 ms
16,848 KB
testcase_36 AC 27 ms
10,292 KB
testcase_37 AC 46 ms
16,276 KB
testcase_38 AC 43 ms
16,056 KB
testcase_39 AC 52 ms
16,580 KB
testcase_40 AC 19 ms
8,608 KB
testcase_41 WA -
testcase_42 AC 50 ms
16,532 KB
testcase_43 AC 51 ms
16,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from sys import stdin

def primes235(limit):
    yield 2; yield 3; yield 5
    if limit < 7: return
    modPrms = [7,11,13,17,19,23,29,31]
    gaps = [4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6]
    ndxs = [0,0,0,0,1,1,2,2,2,2,3,3,4,4,4,4,5,5,5,5,5,5,6,6,7,7,7,7,7,7]
    lmtbf = (limit + 23) // 30 * 8 - 1
    lmtsqrt = (int(limit ** 0.5) - 7)
    lmtsqrt = lmtsqrt // 30 * 8 + ndxs[lmtsqrt % 30]
    buf = [True] * (lmtbf + 1)
    for i in range(lmtsqrt + 1):
        if buf[i]:
            ci = i & 7; p = 30 * (i >> 3) + modPrms[ci]
            s = p * p - 7; p8 = p << 3
            for j in range(8):
                c = s // 30 * 8 + ndxs[s % 30]
                buf[c::p8] = [False] * ((lmtbf - c) // p8 + 1)
                s += p * gaps[ci]; ci += 1
    for i in range(lmtbf - 6 + (ndxs[(limit - 7) % 30])):
        if buf[i]: yield (30 * (i >> 3) + modPrms[i & 7])

def main():
    N = int(input())

    primes = list(primes235(N))
    r2 = defaultdict(int)
    for i in primes:
        r2[i*i] = 1

    ans = 0
    for i in primes:
        if r2[2+i]:
            if i == 2:
                ans += 1
            else:
                ans += 2
    print(ans)

input = lambda: stdin.readline()
main()
0