結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2023-07-07 17:11:14 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 727 ms / 1,000 ms |
| コード長 | 750 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 101,484 KB |
| 最終ジャッジ日時 | 2024-10-03 15:51:39 |
| 合計ジャッジ時間 | 27,922 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 42 |
ソースコード
#!/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))
maspy