結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-27 21:32:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 663 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 91,116 KB
最終ジャッジ日時 2024-05-01 01:47:26
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
87,924 KB
testcase_01 AC 118 ms
87,808 KB
testcase_02 AC 123 ms
90,500 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 116 ms
87,680 KB
testcase_06 AC 116 ms
88,740 KB
testcase_07 AC 124 ms
87,680 KB
testcase_08 AC 119 ms
87,284 KB
testcase_09 AC 124 ms
87,936 KB
testcase_10 AC 124 ms
88,580 KB
testcase_11 AC 123 ms
89,344 KB
testcase_12 AC 131 ms
90,296 KB
testcase_13 AC 126 ms
90,752 KB
testcase_14 AC 125 ms
91,116 KB
testcase_15 AC 126 ms
90,368 KB
testcase_16 AC 131 ms
90,868 KB
testcase_17 AC 133 ms
90,368 KB
testcase_18 AC 127 ms
90,788 KB
testcase_19 AC 130 ms
88,832 KB
testcase_20 AC 130 ms
90,404 KB
testcase_21 AC 131 ms
88,320 KB
testcase_22 AC 121 ms
88,472 KB
testcase_23 AC 128 ms
90,496 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 <= 1 <= 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