結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー titiatitia
提出日時 2021-08-27 21:31:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 150,076 KB
最終ジャッジ日時 2023-08-13 08:04:05
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
149,588 KB
testcase_01 AC 212 ms
149,648 KB
testcase_02 AC 256 ms
149,744 KB
testcase_03 AC 206 ms
149,740 KB
testcase_04 AC 199 ms
149,548 KB
testcase_05 AC 202 ms
149,764 KB
testcase_06 AC 206 ms
149,816 KB
testcase_07 AC 208 ms
149,900 KB
testcase_08 AC 216 ms
149,768 KB
testcase_09 AC 209 ms
149,596 KB
testcase_10 AC 194 ms
149,364 KB
testcase_11 AC 204 ms
149,824 KB
testcase_12 AC 250 ms
149,752 KB
testcase_13 AC 230 ms
150,076 KB
testcase_14 AC 235 ms
149,992 KB
testcase_15 AC 248 ms
149,692 KB
testcase_16 AC 221 ms
149,960 KB
testcase_17 AC 215 ms
149,720 KB
testcase_18 AC 216 ms
149,704 KB
testcase_19 AC 270 ms
149,820 KB
testcase_20 AC 232 ms
149,752 KB
testcase_21 AC 272 ms
149,732 KB
testcase_22 AC 212 ms
149,904 KB
testcase_23 AC 212 ms
149,856 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