結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー maspy
提出日時 2020-04-08 01:52:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 749 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 93,328 KB
最終ジャッジ日時 2024-07-08 12:48:44
合計ジャッジ時間 24,816 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other RE * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


L, H = map(int, read().split())
U = 10 ** 5 + 10
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p * p >= U:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]


def solve(L, R):
    global primes
    primes = primes[primes ** 2 <= R]
    p = primes[-1]
    if p * p >= L:
        L = p * p
    n = R - L + 1
    min_p = np.zeros(n, np.int64)
    for p in primes[::-1]:
        i = (-L) % p
        min_p[i::p] = p
    return L + np.where(min_p == min_p.max())[0][-1]


print(solve(L, H))
0