結果

問題 No.843 Triple Primes
ユーザー toyuzukotoyuzuko
提出日時 2020-04-21 21:18:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,613 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-17 15:33:32
合計ジャッジ時間 29,657 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 1,396 ms
16,384 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 35 ms
10,752 KB
testcase_07 AC 1,037 ms
15,232 KB
testcase_08 AC 1,212 ms
15,744 KB
testcase_09 AC 1,460 ms
16,256 KB
testcase_10 AC 1,164 ms
15,360 KB
testcase_11 AC 1,232 ms
15,872 KB
testcase_12 AC 1,309 ms
16,256 KB
testcase_13 AC 1,205 ms
16,000 KB
testcase_14 AC 1,237 ms
16,256 KB
testcase_15 AC 1,030 ms
15,360 KB
testcase_16 AC 1,103 ms
15,488 KB
testcase_17 AC 26 ms
10,752 KB
testcase_18 AC 24 ms
10,752 KB
testcase_19 AC 24 ms
10,880 KB
testcase_20 AC 250 ms
12,288 KB
testcase_21 AC 138 ms
11,648 KB
testcase_22 AC 657 ms
13,952 KB
testcase_23 AC 632 ms
14,080 KB
testcase_24 AC 266 ms
12,416 KB
testcase_25 AC 195 ms
11,904 KB
testcase_26 AC 1,293 ms
16,384 KB
testcase_27 AC 58 ms
11,136 KB
testcase_28 AC 1,310 ms
16,000 KB
testcase_29 AC 296 ms
12,672 KB
testcase_30 AC 1,260 ms
16,256 KB
testcase_31 AC 81 ms
11,264 KB
testcase_32 AC 50 ms
11,136 KB
testcase_33 AC 331 ms
12,800 KB
testcase_34 AC 546 ms
13,568 KB
testcase_35 AC 1,375 ms
16,384 KB
testcase_36 AC 181 ms
11,776 KB
testcase_37 AC 1,114 ms
15,232 KB
testcase_38 AC 844 ms
14,464 KB
testcase_39 AC 1,613 ms
16,256 KB
testcase_40 AC 28 ms
10,752 KB
testcase_41 AC 25 ms
10,752 KB
testcase_42 AC 1,165 ms
15,616 KB
testcase_43 AC 1,190 ms
15,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    res = [True for _ in range(n + 1)]
    res[0] = False
    res[1] = False
    i = 2
    while i * i <= n:
        if res[i]:
            for j in range(i * 2, n + 1, i):
                res[j] = False
        i += 1
    return res

N = int(input())

S = sieve(N)

P = [i for i in range(N + 1) if S[i]]
R = []

for i in range(N + 1):
    if i**2 > 2 * N:
        break
    if S[i]:
        R.append(i**2)

res = 0

for p in P:
    for r in R:
        q = r - p
        if 0 < q <= N and S[q]:
            res += 1

print(res)
0