結果

問題 No.843 Triple Primes
ユーザー 👑 KazunKazun
提出日時 2020-10-03 03:32:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 88,132 KB
最終ジャッジ日時 2023-09-25 04:38:22
合計ジャッジ時間 7,351 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,372 KB
testcase_01 AC 106 ms
87,968 KB
testcase_02 AC 83 ms
75,548 KB
testcase_03 AC 78 ms
75,752 KB
testcase_04 AC 80 ms
76,156 KB
testcase_05 AC 77 ms
75,832 KB
testcase_06 AC 80 ms
76,124 KB
testcase_07 AC 98 ms
85,164 KB
testcase_08 AC 100 ms
86,428 KB
testcase_09 AC 106 ms
87,836 KB
testcase_10 AC 100 ms
85,332 KB
testcase_11 AC 102 ms
86,704 KB
testcase_12 AC 104 ms
87,840 KB
testcase_13 AC 100 ms
86,688 KB
testcase_14 AC 101 ms
86,620 KB
testcase_15 AC 99 ms
85,224 KB
testcase_16 AC 101 ms
85,472 KB
testcase_17 AC 72 ms
71,324 KB
testcase_18 AC 75 ms
71,304 KB
testcase_19 AC 76 ms
71,244 KB
testcase_20 AC 88 ms
78,128 KB
testcase_21 AC 81 ms
76,732 KB
testcase_22 AC 90 ms
81,900 KB
testcase_23 AC 93 ms
82,256 KB
testcase_24 AC 84 ms
78,260 KB
testcase_25 AC 82 ms
77,412 KB
testcase_26 AC 101 ms
87,920 KB
testcase_27 AC 79 ms
76,448 KB
testcase_28 AC 105 ms
86,740 KB
testcase_29 AC 86 ms
78,388 KB
testcase_30 AC 102 ms
87,780 KB
testcase_31 AC 80 ms
76,608 KB
testcase_32 AC 79 ms
76,348 KB
testcase_33 AC 85 ms
78,612 KB
testcase_34 AC 91 ms
81,296 KB
testcase_35 AC 106 ms
88,132 KB
testcase_36 AC 85 ms
77,100 KB
testcase_37 AC 100 ms
84,956 KB
testcase_38 AC 93 ms
82,876 KB
testcase_39 AC 100 ms
87,472 KB
testcase_40 AC 72 ms
71,256 KB
testcase_41 AC 72 ms
71,340 KB
testcase_42 AC 100 ms
86,128 KB
testcase_43 AC 101 ms
86,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#エラトステネスの篩
def Sieve_of_Eratosthenes(N,mode=False):
    """Nまでのエラトステネスの篩を実行

    N:自然数
    mode:False->素数のリスト,True->素数かどうかのリスト
    (False->[2,3,5,...],True->[False,False,True,True,False,True,...])
    """

    T=[True]*(N+1)
    T[0]=T[1]=0
    a=2
    while a*a<=N:
        if T[a]:
            b=a*a
            while b<=N:
                T[b]=False
                b+=a
        a+=1

    if mode:
        return T
    else:
        return [k for k in range(N+1) if T[k]]
#================================================
N=int(input())

if N==1:
    print(0)
    exit()

T=Sieve_of_Eratosthenes(N)[1:]
U=set([r*r for r in T])
X=1
for q in T:
    if 2+q in U:
        X+=2
print(X)
0