結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-27 21:34:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 102,664 KB
最終ジャッジ日時 2023-08-13 08:09:36
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
102,412 KB
testcase_01 AC 163 ms
102,420 KB
testcase_02 AC 165 ms
102,452 KB
testcase_03 AC 158 ms
102,564 KB
testcase_04 AC 158 ms
102,412 KB
testcase_05 AC 154 ms
102,408 KB
testcase_06 AC 165 ms
102,572 KB
testcase_07 AC 161 ms
102,368 KB
testcase_08 AC 162 ms
102,324 KB
testcase_09 AC 167 ms
102,188 KB
testcase_10 AC 167 ms
102,516 KB
testcase_11 AC 166 ms
102,432 KB
testcase_12 AC 163 ms
102,228 KB
testcase_13 AC 167 ms
102,516 KB
testcase_14 AC 165 ms
102,452 KB
testcase_15 AC 171 ms
102,504 KB
testcase_16 AC 167 ms
102,664 KB
testcase_17 AC 173 ms
102,456 KB
testcase_18 AC 165 ms
102,456 KB
testcase_19 AC 165 ms
102,492 KB
testcase_20 AC 162 ms
102,584 KB
testcase_21 AC 160 ms
102,568 KB
testcase_22 AC 158 ms
102,480 KB
testcase_23 AC 166 ms
102,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def sieve(n):
    ass = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            ass.append(i)
    return(ass)

P = sieve(2*10**6)

l, r = map(int, input().split())
ans = 0
for p in P:
    if p == 2:
        if l <= 2 <= r:
            ans += 1
    else:
        a = (p-1)//2
        b = (p+1)//2
        if l <= a and b <= r:
            ans += 1
        if l <= p <= r:
            ans += 1
print(ans)
0