結果

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

ソースコード

diff #

#エネストラバージョン
n=int(input())
if n==1:
    print(0)
    exit()
elif n==2:
    print(1)
    exit()
TF=[0,1]*(n//2+1)
TF[1]=0
TF[2]=1
primes=[]
for p in range(3,n+1):
    if TF[p]==0:continue
    primes.append(p)
    for i in range(p**2,n+1,p):
        TF[i]=0
cnt=0
for r in primes:
    p=r**2-2
    if p>n:
        break
    if TF[p]:
        cnt+=1
print(cnt*2+1)
0