結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー KudeKude
提出日時 2021-08-27 21:27:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 99,468 KB
最終ジャッジ日時 2024-05-01 01:36:39
合計ジャッジ時間 3,458 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
94,192 KB
testcase_01 AC 87 ms
93,736 KB
testcase_02 AC 103 ms
98,296 KB
testcase_03 AC 92 ms
93,824 KB
testcase_04 AC 87 ms
94,148 KB
testcase_05 AC 86 ms
94,336 KB
testcase_06 AC 96 ms
97,156 KB
testcase_07 AC 93 ms
94,944 KB
testcase_08 AC 91 ms
94,028 KB
testcase_09 AC 99 ms
95,668 KB
testcase_10 AC 99 ms
94,968 KB
testcase_11 AC 101 ms
97,500 KB
testcase_12 AC 108 ms
98,388 KB
testcase_13 AC 101 ms
98,636 KB
testcase_14 AC 98 ms
97,684 KB
testcase_15 AC 100 ms
97,896 KB
testcase_16 AC 95 ms
97,804 KB
testcase_17 AC 97 ms
97,492 KB
testcase_18 AC 94 ms
98,432 KB
testcase_19 AC 110 ms
96,956 KB
testcase_20 AC 100 ms
99,244 KB
testcase_21 AC 109 ms
99,468 KB
testcase_22 AC 89 ms
93,916 KB
testcase_23 AC 96 ms
98,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Primes_MAX = 2 * 10 ** 6 + 100
Primes = []
Sieve = [0] * Primes_MAX
Sieve[0] = Sieve[1] = -1
for p in range(2, Primes_MAX):
    if not Sieve[p]:
        Primes.append(p)
        Sieve[p] = p
        for q in range(p * p, Primes_MAX, p):
            if not Sieve[q]:
                Sieve[q] = p

l, r = map(int, input().split())
ans = 0
p = 0
for i in range(l, r):
    x = i + i + 1
    while Primes[p] < x:
        p += 1
    ans += Primes[p] == x

for i in range(l, r + 1):
    ans += Sieve[i] == i

print(ans)
0