結果

問題 No.843 Triple Primes
ユーザー stngstng
提出日時 2022-07-16 16:10:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 87,748 KB
最終ジャッジ日時 2023-09-11 01:10:49
合計ジャッジ時間 10,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,464 KB
testcase_01 AC 263 ms
87,512 KB
testcase_02 AC 79 ms
76,432 KB
testcase_03 AC 80 ms
76,688 KB
testcase_04 AC 83 ms
76,864 KB
testcase_05 AC 85 ms
76,536 KB
testcase_06 AC 82 ms
76,800 KB
testcase_07 AC 195 ms
84,952 KB
testcase_08 AC 217 ms
86,116 KB
testcase_09 AC 262 ms
87,748 KB
testcase_10 AC 202 ms
85,296 KB
testcase_11 AC 228 ms
86,404 KB
testcase_12 AC 255 ms
87,408 KB
testcase_13 AC 241 ms
86,696 KB
testcase_14 AC 240 ms
86,556 KB
testcase_15 AC 197 ms
85,184 KB
testcase_16 AC 202 ms
85,272 KB
testcase_17 AC 71 ms
71,836 KB
testcase_18 AC 73 ms
71,396 KB
testcase_19 AC 71 ms
71,744 KB
testcase_20 AC 108 ms
78,552 KB
testcase_21 AC 99 ms
77,072 KB
testcase_22 AC 140 ms
81,752 KB
testcase_23 AC 145 ms
82,428 KB
testcase_24 AC 111 ms
78,412 KB
testcase_25 AC 124 ms
77,712 KB
testcase_26 AC 262 ms
87,500 KB
testcase_27 AC 89 ms
76,936 KB
testcase_28 AC 247 ms
86,496 KB
testcase_29 AC 111 ms
79,040 KB
testcase_30 AC 258 ms
87,688 KB
testcase_31 AC 92 ms
76,724 KB
testcase_32 AC 94 ms
76,960 KB
testcase_33 AC 114 ms
79,152 KB
testcase_34 AC 134 ms
81,552 KB
testcase_35 AC 265 ms
87,496 KB
testcase_36 AC 114 ms
77,832 KB
testcase_37 AC 185 ms
84,728 KB
testcase_38 AC 157 ms
82,864 KB
testcase_39 AC 249 ms
87,304 KB
testcase_40 AC 72 ms
71,336 KB
testcase_41 AC 71 ms
71,580 KB
testcase_42 AC 208 ms
86,268 KB
testcase_43 AC 231 ms
86,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def sieve_of_eratosthenes(n):
    prime = [True for i in range(n+1)]
    prime[0] = False
    prime[1] = False

    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if prime[i]:
            for j in range(2*i, n+1, i):
                prime[j] = False

    return prime

n = int(input())
prm = sieve_of_eratosthenes(n)
pri = []
pset = set()
for i in range(n+1):
    if prm[i] == True:
        pri.append(i)
        pset.add(i)

ans = 0

for i in range(len(pri)):
    r2 = pri[len(pri)-1-i]**2
    if r2 > 10**6:
        continue
    for j in range(len(pri)):
        if r2-pri[j] in pset:
            ans += 1

print(ans)
0