結果

問題 No.843 Triple Primes
ユーザー maspy
提出日時 2020-01-21 14:13:53
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 573 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 44,596 KB
最終ジャッジ日時 2024-07-05 16:40:10
合計ジャッジ時間 22,466 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(read())

U = 5 * 10**5
is_prime = np.zeros(U,np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3,U,2):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p+p] = 0

primes = np.where(is_prime)[0]

answer = 0
# (p,q,2)
if N >= 2:
    answer += 1
# (2,p,r) and (p,2,r)
primes = primes[primes <= N]
primes = primes[1:]
r = primes[primes**2 - 2 <= N]
answer += 2 * is_prime[r**2 - 2].sum()
print(answer)
0