結果

問題 No.843 Triple Primes
ユーザー ssmkzk
提出日時 2019-07-02 14:08:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 30,848 KB
最終ジャッジ日時 2024-09-19 14:16:21
合計ジャッジ時間 5,826 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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