結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tcltktcltk
提出日時 2021-10-16 20:43:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 113,596 KB
最終ジャッジ日時 2023-10-17 22:17:41
合計ジャッジ時間 6,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
85,916 KB
testcase_01 AC 126 ms
85,916 KB
testcase_02 AC 269 ms
111,936 KB
testcase_03 AC 129 ms
85,916 KB
testcase_04 AC 128 ms
85,916 KB
testcase_05 AC 127 ms
85,920 KB
testcase_06 AC 138 ms
88,256 KB
testcase_07 AC 131 ms
86,532 KB
testcase_08 AC 134 ms
86,824 KB
testcase_09 AC 139 ms
88,248 KB
testcase_10 AC 140 ms
88,232 KB
testcase_11 AC 138 ms
88,260 KB
testcase_12 AC 251 ms
111,672 KB
testcase_13 AC 194 ms
100,084 KB
testcase_14 AC 231 ms
108,404 KB
testcase_15 AC 236 ms
108,656 KB
testcase_16 AC 179 ms
96,712 KB
testcase_17 AC 188 ms
98,220 KB
testcase_18 AC 183 ms
99,424 KB
testcase_19 AC 253 ms
110,412 KB
testcase_20 AC 203 ms
103,260 KB
testcase_21 AC 260 ms
113,596 KB
testcase_22 AC 255 ms
113,596 KB
testcase_23 AC 255 ms
113,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """2 9
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def get_primes(N):
    a = [True] * (N + 1)
    l = []
    for n in range(2, N + 1):
        if a[n]:
            l.append(n)
            for i in range(n+n, N + 1, n):
                a[i] = False
    return l

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

primes = get_primes(2*R+2)

i1 = bisect.bisect_left(primes, L)
j1 = bisect.bisect_left(primes, R+1)
ans = j1 - i1
if L < R:
    i2 = bisect.bisect_left(primes, 2*L+1)
    j2 = bisect.bisect_left(primes, 2*(R-1)+1+1)
    ans += j2 - i2
print(ans)

0