結果

問題 No.843 Triple Primes
ユーザー 👑 H20H20
提出日時 2021-01-07 10:55:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 91,164 KB
最終ジャッジ日時 2024-04-25 13:37:08
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,344 KB
testcase_01 AC 147 ms
90,628 KB
testcase_02 AC 46 ms
62,092 KB
testcase_03 AC 45 ms
62,176 KB
testcase_04 AC 46 ms
62,656 KB
testcase_05 AC 46 ms
62,848 KB
testcase_06 AC 47 ms
62,104 KB
testcase_07 AC 123 ms
84,904 KB
testcase_08 AC 130 ms
87,148 KB
testcase_09 AC 149 ms
91,132 KB
testcase_10 AC 126 ms
87,976 KB
testcase_11 AC 138 ms
90,648 KB
testcase_12 AC 142 ms
91,164 KB
testcase_13 AC 143 ms
90,560 KB
testcase_14 AC 143 ms
90,724 KB
testcase_15 AC 125 ms
87,644 KB
testcase_16 AC 124 ms
87,068 KB
testcase_17 AC 36 ms
53,564 KB
testcase_18 AC 36 ms
53,748 KB
testcase_19 AC 36 ms
52,204 KB
testcase_20 AC 69 ms
70,192 KB
testcase_21 AC 58 ms
66,376 KB
testcase_22 AC 95 ms
79,636 KB
testcase_23 AC 98 ms
79,752 KB
testcase_24 AC 70 ms
71,088 KB
testcase_25 AC 63 ms
68,648 KB
testcase_26 AC 148 ms
90,596 KB
testcase_27 AC 50 ms
63,956 KB
testcase_28 AC 143 ms
90,292 KB
testcase_29 AC 72 ms
71,252 KB
testcase_30 AC 145 ms
90,196 KB
testcase_31 AC 52 ms
64,588 KB
testcase_32 AC 49 ms
62,536 KB
testcase_33 AC 77 ms
72,808 KB
testcase_34 AC 113 ms
77,764 KB
testcase_35 AC 146 ms
90,344 KB
testcase_36 AC 60 ms
67,008 KB
testcase_37 AC 116 ms
84,428 KB
testcase_38 AC 105 ms
81,448 KB
testcase_39 AC 142 ms
90,600 KB
testcase_40 AC 37 ms
53,312 KB
testcase_41 AC 36 ms
52,504 KB
testcase_42 AC 128 ms
87,612 KB
testcase_43 AC 137 ms
89,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

N = int(input())
_,t = sieve(2*N)
s=set(t)
ppow = []
lent = len(t)
i = 0
while  i<lent and t[i]**2<=2*N:
    ppow.append(t[i]**2)
    i+=1
ans = 0

for p in ppow:
    for j in range(lent):
        if p - t[j] in s and p - t[j]<=N and t[j]<=N:
            ans+=1
        if t[j]>=p:
            break
print(ans)
0