結果

問題 No.843 Triple Primes
ユーザー convexineqconvexineq
提出日時 2019-06-28 21:31:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 19,944 KB
最終ジャッジ日時 2023-10-19 17:30:24
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,236 KB
testcase_01 AC 171 ms
19,944 KB
testcase_02 AC 30 ms
10,324 KB
testcase_03 AC 30 ms
10,340 KB
testcase_04 AC 32 ms
10,416 KB
testcase_05 AC 30 ms
10,352 KB
testcase_06 AC 32 ms
10,416 KB
testcase_07 AC 137 ms
18,364 KB
testcase_08 AC 149 ms
18,544 KB
testcase_09 AC 166 ms
19,932 KB
testcase_10 AC 141 ms
18,176 KB
testcase_11 AC 156 ms
19,748 KB
testcase_12 AC 163 ms
19,880 KB
testcase_13 AC 158 ms
19,812 KB
testcase_14 AC 163 ms
19,816 KB
testcase_15 AC 139 ms
18,132 KB
testcase_16 AC 146 ms
18,160 KB
testcase_17 AC 29 ms
10,160 KB
testcase_18 AC 30 ms
10,236 KB
testcase_19 AC 29 ms
10,188 KB
testcase_20 AC 64 ms
12,848 KB
testcase_21 AC 50 ms
11,808 KB
testcase_22 AC 106 ms
16,544 KB
testcase_23 AC 108 ms
16,604 KB
testcase_24 AC 66 ms
12,944 KB
testcase_25 AC 58 ms
12,144 KB
testcase_26 AC 163 ms
19,928 KB
testcase_27 AC 37 ms
10,584 KB
testcase_28 AC 157 ms
19,836 KB
testcase_29 AC 68 ms
13,092 KB
testcase_30 AC 162 ms
19,892 KB
testcase_31 AC 41 ms
11,072 KB
testcase_32 AC 36 ms
10,520 KB
testcase_33 AC 73 ms
13,300 KB
testcase_34 AC 100 ms
15,648 KB
testcase_35 AC 167 ms
19,936 KB
testcase_36 AC 55 ms
12,104 KB
testcase_37 AC 135 ms
18,092 KB
testcase_38 AC 118 ms
17,580 KB
testcase_39 AC 160 ms
19,856 KB
testcase_40 AC 29 ms
10,236 KB
testcase_41 AC 29 ms
10,160 KB
testcase_42 AC 144 ms
18,228 KB
testcase_43 AC 158 ms
19,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

n=int(input())
if n==1: print(0); exit()



def Eratosthenes(N):
    N+=1
    is_prime_list = [True]*N
    is_prime_list[0], is_prime_list[1] = False, False
    for j in range(4,N,2): is_prime_list[j] = False
    m = min(int(N**0.5)+10,N)
    for i in range(3,m,2):
        if is_prime_list[i]:
            for j in range(i*i,N,i):
                is_prime_list[j] = False
    return [number for number, TF in enumerate(is_prime_list) if TF]

heiho = {i*i for i in Eratosthenes(n)}

ans = 0
for i in Eratosthenes(n+1):
    if i+2 in heiho:
        ans += 1
#        print(i)

print(ans*2-1)
0