結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー rlangevinrlangevin
提出日時 2022-12-31 22:19:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 115,044 KB
最終ジャッジ日時 2023-08-17 21:28:51
合計ジャッジ時間 5,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
114,592 KB
testcase_01 AC 165 ms
114,464 KB
testcase_02 AC 220 ms
115,016 KB
testcase_03 AC 158 ms
114,524 KB
testcase_04 AC 160 ms
114,568 KB
testcase_05 AC 165 ms
114,664 KB
testcase_06 AC 169 ms
114,924 KB
testcase_07 AC 161 ms
114,588 KB
testcase_08 AC 166 ms
114,668 KB
testcase_09 AC 163 ms
114,464 KB
testcase_10 AC 162 ms
114,552 KB
testcase_11 AC 165 ms
114,976 KB
testcase_12 AC 215 ms
114,884 KB
testcase_13 AC 182 ms
114,772 KB
testcase_14 AC 185 ms
114,980 KB
testcase_15 AC 194 ms
115,044 KB
testcase_16 AC 172 ms
114,984 KB
testcase_17 AC 167 ms
114,980 KB
testcase_18 AC 165 ms
114,900 KB
testcase_19 AC 221 ms
114,848 KB
testcase_20 AC 176 ms
115,044 KB
testcase_21 AC 229 ms
114,852 KB
testcase_22 AC 160 ms
114,640 KB
testcase_23 AC 168 ms
114,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *


def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return S


L, R = map(int, input().split())
S = Sieve(2020202)
ans = 0
for i in range(L, R + 1):
    if i in S:
        ans += 1
        
for i in range(L, R):
    if 2 * i + 1 in S:
        ans += 1
print(ans)
0