結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-27 21:34:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 92,172 KB
最終ジャッジ日時 2024-05-01 01:50:40
合計ジャッジ時間 4,553 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
88,260 KB
testcase_01 AC 138 ms
89,352 KB
testcase_02 AC 144 ms
90,664 KB
testcase_03 AC 137 ms
87,656 KB
testcase_04 AC 142 ms
87,764 KB
testcase_05 AC 136 ms
88,596 KB
testcase_06 AC 139 ms
88,516 KB
testcase_07 AC 140 ms
88,752 KB
testcase_08 AC 139 ms
88,016 KB
testcase_09 AC 139 ms
88,612 KB
testcase_10 AC 142 ms
88,948 KB
testcase_11 AC 144 ms
89,088 KB
testcase_12 AC 144 ms
90,936 KB
testcase_13 AC 141 ms
90,764 KB
testcase_14 AC 140 ms
90,812 KB
testcase_15 AC 143 ms
92,172 KB
testcase_16 AC 143 ms
91,076 KB
testcase_17 AC 146 ms
91,964 KB
testcase_18 AC 146 ms
90,996 KB
testcase_19 AC 140 ms
89,176 KB
testcase_20 AC 145 ms
91,344 KB
testcase_21 AC 142 ms
88,556 KB
testcase_22 AC 137 ms
88,216 KB
testcase_23 AC 152 ms
91,080 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