結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tcltktcltk
提出日時 2021-10-16 20:39:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 113,604 KB
最終ジャッジ日時 2023-10-17 22:17:32
合計ジャッジ時間 5,681 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
85,932 KB
testcase_01 AC 128 ms
85,936 KB
testcase_02 AC 290 ms
111,940 KB
testcase_03 AC 129 ms
85,932 KB
testcase_04 WA -
testcase_05 AC 128 ms
85,932 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 136 ms
86,616 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 141 ms
88,264 KB
testcase_12 AC 269 ms
111,680 KB
testcase_13 AC 197 ms
100,084 KB
testcase_14 AC 242 ms
108,404 KB
testcase_15 AC 248 ms
108,664 KB
testcase_16 AC 175 ms
96,716 KB
testcase_17 AC 185 ms
98,220 KB
testcase_18 AC 187 ms
99,428 KB
testcase_19 AC 256 ms
110,416 KB
testcase_20 AC 203 ms
103,264 KB
testcase_21 AC 264 ms
113,604 KB
testcase_22 AC 279 ms
113,604 KB
testcase_23 AC 274 ms
113,440 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 = """1 1
# """
# 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)
    ans += j2 - i2
print(ans)

0