結果

問題 No.843 Triple Primes
ユーザー ssmkzkssmkzk
提出日時 2019-07-02 14:08:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 11,828 KB
実行使用メモリ 30,172 KB
最終ジャッジ日時 2023-10-19 17:57:42
合計ジャッジ時間 5,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,184 KB
testcase_01 AC 171 ms
30,172 KB
testcase_02 AC 30 ms
10,416 KB
testcase_03 AC 31 ms
10,340 KB
testcase_04 AC 35 ms
10,544 KB
testcase_05 AC 30 ms
10,368 KB
testcase_06 AC 31 ms
10,572 KB
testcase_07 AC 143 ms
26,128 KB
testcase_08 AC 153 ms
27,720 KB
testcase_09 AC 173 ms
30,064 KB
testcase_10 AC 149 ms
26,868 KB
testcase_11 AC 160 ms
28,524 KB
testcase_12 AC 167 ms
29,632 KB
testcase_13 AC 164 ms
29,092 KB
testcase_14 AC 165 ms
29,116 KB
testcase_15 AC 145 ms
26,384 KB
testcase_16 AC 147 ms
26,748 KB
testcase_17 AC 29 ms
10,184 KB
testcase_18 AC 30 ms
10,184 KB
testcase_19 AC 29 ms
10,184 KB
testcase_20 AC 64 ms
15,496 KB
testcase_21 AC 47 ms
12,972 KB
testcase_22 AC 103 ms
21,228 KB
testcase_23 AC 107 ms
21,688 KB
testcase_24 AC 65 ms
15,760 KB
testcase_25 AC 56 ms
14,292 KB
testcase_26 AC 174 ms
30,016 KB
testcase_27 AC 37 ms
11,224 KB
testcase_28 AC 170 ms
29,288 KB
testcase_29 AC 69 ms
16,024 KB
testcase_30 AC 172 ms
29,736 KB
testcase_31 AC 41 ms
12,012 KB
testcase_32 AC 36 ms
11,224 KB
testcase_33 AC 75 ms
16,816 KB
testcase_34 AC 100 ms
20,356 KB
testcase_35 AC 174 ms
30,076 KB
testcase_36 AC 53 ms
14,028 KB
testcase_37 AC 136 ms
25,516 KB
testcase_38 AC 122 ms
23,124 KB
testcase_39 AC 175 ms
29,452 KB
testcase_40 AC 30 ms
10,184 KB
testcase_41 AC 30 ms
10,184 KB
testcase_42 AC 150 ms
27,252 KB
testcase_43 AC 167 ms
28,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import bisect

N = int(input())

def SoE(x):
    if x < 2:
        return []
    
    l = [i for i in range(x + 1)]
    l[1] = 0
    
    for i in l:
        if i > math.sqrt(x):
            break
        if i == 0:
            continue
        for j in range(2 * i , x + 1, i):
            l[j] = 0
    
    return [i for i in l if i != 0]

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return 2
    else:
        return 0

prime = SoE(N)
ans = 0
for l_i in prime:
    a = pow(l_i,2) - 2
    ans += index(prime,a)
if N == 1:
    print(ans)
else:
    print(ans - 1)
0