結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー titiatitia
提出日時 2021-08-27 21:31:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 137,972 KB
最終ジャッジ日時 2024-05-01 01:45:19
合計ジャッジ時間 6,440 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
135,664 KB
testcase_01 AC 201 ms
135,968 KB
testcase_02 AC 260 ms
137,500 KB
testcase_03 AC 203 ms
135,796 KB
testcase_04 AC 211 ms
135,920 KB
testcase_05 AC 210 ms
136,104 KB
testcase_06 AC 212 ms
137,692 KB
testcase_07 AC 209 ms
135,928 KB
testcase_08 AC 219 ms
135,820 KB
testcase_09 AC 213 ms
135,976 KB
testcase_10 AC 215 ms
136,088 KB
testcase_11 AC 217 ms
137,972 KB
testcase_12 AC 257 ms
137,668 KB
testcase_13 AC 232 ms
137,676 KB
testcase_14 AC 236 ms
137,680 KB
testcase_15 AC 225 ms
137,468 KB
testcase_16 AC 207 ms
137,456 KB
testcase_17 AC 209 ms
137,488 KB
testcase_18 AC 201 ms
137,512 KB
testcase_19 AC 264 ms
137,360 KB
testcase_20 AC 206 ms
137,660 KB
testcase_21 AC 266 ms
137,788 KB
testcase_22 AC 201 ms
135,788 KB
testcase_23 AC 213 ms
137,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import math

x=3*10**6

L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

S=set(Primes)

L,R=map(int,input().split())

ANS=0
for i in range(L,R+1):
    if i in S:
        ANS+=1

for i in range(L,R):
    if i+i+1 in S:
        ANS+=1

print(ANS)

0