結果

問題 No.843 Triple Primes
ユーザー tktk_snsntktk_snsn
提出日時 2021-04-24 00:48:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 29,944 KB
最終ジャッジ日時 2023-09-17 13:17:59
合計ジャッジ時間 24,245 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,352 KB
testcase_01 AC 1,036 ms
29,828 KB
testcase_02 AC 20 ms
8,756 KB
testcase_03 AC 19 ms
8,496 KB
testcase_04 AC 23 ms
8,860 KB
testcase_05 AC 19 ms
8,632 KB
testcase_06 AC 23 ms
8,800 KB
testcase_07 AC 758 ms
24,812 KB
testcase_08 AC 878 ms
25,212 KB
testcase_09 AC 1,049 ms
29,936 KB
testcase_10 AC 829 ms
24,972 KB
testcase_11 AC 936 ms
25,528 KB
testcase_12 AC 962 ms
29,776 KB
testcase_13 AC 951 ms
29,692 KB
testcase_14 AC 965 ms
29,488 KB
testcase_15 AC 776 ms
24,888 KB
testcase_16 AC 785 ms
24,956 KB
testcase_17 AC 17 ms
8,172 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 187 ms
13,868 KB
testcase_21 AC 97 ms
12,176 KB
testcase_22 AC 465 ms
19,416 KB
testcase_23 AC 523 ms
19,500 KB
testcase_24 AC 206 ms
14,092 KB
testcase_25 AC 159 ms
13,416 KB
testcase_26 AC 1,015 ms
29,848 KB
testcase_27 AC 42 ms
9,648 KB
testcase_28 AC 1,064 ms
29,884 KB
testcase_29 AC 222 ms
14,492 KB
testcase_30 AC 974 ms
29,944 KB
testcase_31 AC 59 ms
9,988 KB
testcase_32 AC 37 ms
9,376 KB
testcase_33 AC 251 ms
14,896 KB
testcase_34 AC 445 ms
19,144 KB
testcase_35 AC 1,049 ms
29,824 KB
testcase_36 AC 127 ms
12,364 KB
testcase_37 AC 729 ms
20,596 KB
testcase_38 AC 567 ms
21,180 KB
testcase_39 AC 991 ms
29,756 KB
testcase_40 WA -
testcase_41 AC 16 ms
8,268 KB
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import chain


def prime_set(N):
    """
    Nまでの素数のsetを返す
    """
    if N < 4:
        return ({}, {}, {2}, {2, 3})[N]
    Nsq = int(N ** 0.5 + 0.5) + 1
    primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6)))
    for i in range(5, Nsq, 2):
        if i in primes:
            primes -= set(range(i * i, N + 1, i * 2))
    return primes


N = int(input())
R = []
prime = prime_set(N)
for p in prime:
    if p * p < N:
        R.append(p*p)

ans = 0
for p in prime:
    for r in R:
        q = r - p
        if p <= q and q in prime:
            if p == q:
                ans += 1
            else:
                ans += 2
print(ans)
0