結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tcltk
提出日時 2021-10-16 20:43:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 114,392 KB
最終ジャッジ日時 2024-09-17 19:32:06
合計ジャッジ時間 4,721 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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