結果

問題 No.843 Triple Primes
ユーザー rlangevinrlangevin
提出日時 2023-01-03 10:47:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 85,100 KB
最終ジャッジ日時 2023-08-18 00:14:39
合計ジャッジ時間 5,938 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,140 KB
testcase_01 AC 107 ms
85,100 KB
testcase_02 AC 77 ms
75,272 KB
testcase_03 AC 80 ms
75,408 KB
testcase_04 AC 79 ms
75,840 KB
testcase_05 AC 80 ms
75,224 KB
testcase_06 AC 80 ms
75,780 KB
testcase_07 AC 98 ms
82,748 KB
testcase_08 AC 102 ms
83,620 KB
testcase_09 AC 102 ms
84,848 KB
testcase_10 AC 99 ms
82,860 KB
testcase_11 AC 102 ms
83,824 KB
testcase_12 AC 106 ms
84,516 KB
testcase_13 AC 103 ms
84,072 KB
testcase_14 AC 101 ms
84,008 KB
testcase_15 AC 99 ms
82,784 KB
testcase_16 AC 98 ms
82,836 KB
testcase_17 AC 74 ms
71,012 KB
testcase_18 AC 75 ms
71,124 KB
testcase_19 AC 74 ms
71,180 KB
testcase_20 AC 85 ms
77,564 KB
testcase_21 AC 83 ms
76,284 KB
testcase_22 AC 94 ms
80,456 KB
testcase_23 AC 93 ms
80,756 KB
testcase_24 AC 87 ms
77,684 KB
testcase_25 AC 83 ms
77,084 KB
testcase_26 AC 102 ms
84,908 KB
testcase_27 AC 81 ms
75,908 KB
testcase_28 AC 102 ms
83,988 KB
testcase_29 AC 88 ms
78,220 KB
testcase_30 AC 100 ms
84,968 KB
testcase_31 AC 79 ms
76,060 KB
testcase_32 AC 80 ms
75,880 KB
testcase_33 AC 86 ms
78,140 KB
testcase_34 AC 91 ms
80,036 KB
testcase_35 AC 101 ms
84,804 KB
testcase_36 AC 85 ms
76,752 KB
testcase_37 AC 98 ms
82,928 KB
testcase_38 AC 95 ms
81,280 KB
testcase_39 AC 101 ms
84,836 KB
testcase_40 AC 75 ms
71,140 KB
testcase_41 AC 74 ms
71,036 KB
testcase_42 AC 101 ms
83,808 KB
testcase_43 AC 100 ms
83,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return S


N = int(input())
if N == 1:
    print(0)
    exit()
S = set()
prime_set= Sieve(N)
i = 1
while i * i <= N + 2:
    if i in prime_set:
        S.add(i * i)
    i += 1
    

ans = 1
for v in prime_set:
    if v == 2:
        continue
    if v + 2 in S:
        ans += 2
print(ans)
0