結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー KuonAyanoKuonAyano
提出日時 2021-08-27 21:46:59
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,622 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 50,144 KB
最終ジャッジ日時 2023-08-13 08:33:41
合計ジャッジ時間 15,953 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 15 ms
7,816 KB
testcase_02 AC 1,523 ms
49,292 KB
testcase_03 AC 15 ms
8,172 KB
testcase_04 AC 15 ms
7,940 KB
testcase_05 AC 15 ms
7,852 KB
testcase_06 AC 22 ms
8,432 KB
testcase_07 AC 17 ms
8,308 KB
testcase_08 AC 20 ms
8,536 KB
testcase_09 AC 21 ms
8,416 KB
testcase_10 AC 24 ms
8,564 KB
testcase_11 AC 28 ms
8,520 KB
testcase_12 AC 1,502 ms
48,788 KB
testcase_13 AC 756 ms
29,056 KB
testcase_14 AC 1,233 ms
45,792 KB
testcase_15 AC 1,239 ms
46,180 KB
testcase_16 AC 526 ms
25,968 KB
testcase_17 AC 551 ms
27,396 KB
testcase_18 AC 633 ms
28,156 KB
testcase_19 AC 1,444 ms
47,256 KB
testcase_20 AC 890 ms
31,836 KB
testcase_21 AC 1,622 ms
50,144 KB
testcase_22 AC 1,384 ms
49,932 KB
testcase_23 AC 1,355 ms
49,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

L, R = map(int, input().split())

if R == 1:
    print(0)
    exit()

V = 3*R

prime = [True for i in range(V+1)]
p = 2
while (p * p <= V):
    if (prime[p] == True):
        for i in range(p * p, V+1, p):
            prime[i] = False
    p += 1
dee = []
primes = set()
for p in range(2, V+1):
    if prime[p]:
        dee.append(p)
        primes.add(p)

count = 0

for i in range (1, R+1):
    if L <= i <= R and i in primes:
        count+=1
    if L <= i and i+1 <= R and (2*i+1) in primes:
        count+=1
print(count)
0