結果

問題 No.843 Triple Primes
ユーザー daku9640daku9640
提出日時 2019-06-28 22:17:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 11,800 KB
実行使用メモリ 15,624 KB
最終ジャッジ日時 2023-10-19 17:43:56
合計ジャッジ時間 4,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,016 KB
testcase_01 AC 145 ms
15,624 KB
testcase_02 AC 30 ms
10,112 KB
testcase_03 AC 31 ms
10,084 KB
testcase_04 AC 31 ms
10,164 KB
testcase_05 AC 31 ms
10,096 KB
testcase_06 AC 32 ms
10,176 KB
testcase_07 AC 104 ms
14,876 KB
testcase_08 AC 115 ms
15,252 KB
testcase_09 AC 126 ms
15,604 KB
testcase_10 AC 107 ms
14,924 KB
testcase_11 AC 121 ms
15,312 KB
testcase_12 AC 131 ms
15,396 KB
testcase_13 AC 126 ms
15,356 KB
testcase_14 AC 126 ms
15,360 KB
testcase_15 AC 105 ms
14,896 KB
testcase_16 AC 107 ms
14,916 KB
testcase_17 AC 30 ms
10,016 KB
testcase_18 AC 30 ms
10,016 KB
testcase_19 AC 29 ms
10,016 KB
testcase_20 AC 52 ms
11,572 KB
testcase_21 AC 42 ms
11,196 KB
testcase_22 AC 79 ms
14,360 KB
testcase_23 AC 80 ms
14,280 KB
testcase_24 AC 53 ms
11,616 KB
testcase_25 AC 47 ms
11,412 KB
testcase_26 AC 129 ms
15,592 KB
testcase_27 AC 35 ms
10,388 KB
testcase_28 AC 122 ms
15,368 KB
testcase_29 AC 55 ms
11,704 KB
testcase_30 AC 126 ms
15,404 KB
testcase_31 AC 37 ms
10,536 KB
testcase_32 AC 34 ms
10,368 KB
testcase_33 AC 58 ms
11,828 KB
testcase_34 AC 77 ms
14,296 KB
testcase_35 AC 132 ms
15,604 KB
testcase_36 AC 46 ms
11,336 KB
testcase_37 AC 102 ms
14,828 KB
testcase_38 AC 87 ms
14,640 KB
testcase_39 AC 124 ms
15,384 KB
testcase_40 AC 30 ms
10,016 KB
testcase_41 AC 30 ms
10,016 KB
testcase_42 AC 106 ms
15,216 KB
testcase_43 AC 115 ms
15,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime(a):
    if a == 1:
        return []
    li = [2]
    B = [0, 1] * (a // 2 + 1)
    for i in range(3, a + 1, 2):
        if B[i]:
            li.append(i)
            for j in range(i, a + 1, i):
                B[j] = 0
    return li
def solve():
    n = int(input())
    if n == 1:
        return 0
    pri = prime(n)
    R = set(r * r for r in pri)
    ans = 1
    for p in pri[1:]:
        if p + 2 in R:
            ans += 2
    return ans
print(solve())
0