結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kjnhokjnho
提出日時 2016-05-16 23:00:27
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,732 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 31,404 KB
最終ジャッジ日時 2024-04-15 22:39:39
合計ジャッジ時間 5,125 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
17,416 KB
testcase_01 AC 84 ms
11,948 KB
testcase_02 AC 83 ms
11,692 KB
testcase_03 AC 86 ms
11,692 KB
testcase_04 AC 84 ms
11,948 KB
testcase_05 AC 84 ms
11,948 KB
testcase_06 AC 90 ms
11,688 KB
testcase_07 AC 83 ms
11,820 KB
testcase_08 AC 83 ms
11,948 KB
testcase_09 AC 85 ms
11,688 KB
testcase_10 AC 84 ms
11,948 KB
testcase_11 AC 84 ms
11,820 KB
testcase_12 AC 88 ms
11,688 KB
testcase_13 AC 89 ms
11,688 KB
testcase_14 AC 85 ms
11,560 KB
testcase_15 AC 84 ms
11,948 KB
testcase_16 AC 84 ms
11,692 KB
testcase_17 AC 85 ms
11,692 KB
testcase_18 AC 82 ms
11,944 KB
testcase_19 AC 84 ms
11,692 KB
testcase_20 AC 83 ms
11,820 KB
testcase_21 AC 188 ms
11,564 KB
testcase_22 AC 82 ms
11,944 KB
testcase_23 AC 167 ms
11,692 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8

from collections import defaultdict as dd
from collections import Counter
from collections import deque
from string import ascii_lowercase
import math
import array

def main():
    L,H = map(int,raw_input().split())
    root_H = math.sqrt(H)
    primes = sieve_of_eratosthenes(10**5)

    cands = [p for p in primes if L <= p**2 <= H]
    if cands:
        P = max(cands)
        retval = P**2
        for p in [x for x in primes if x > P]:
            if P * p <= H:
                retval = P * p
            else:
                print(retval)
                break

    else:
        min_factor = 1
        retval = 1
        for n in range(L,H+1):
            for p in primes:
                if n%p == 0 and n != p:
                    if p >= min_factor:
                        min_factor = p
                        retval = n
                    break
        print(retval)

def sieve_of_eratosthenes(end, typecode="L"):
    assert end > 1
    # 整数iが素数であるかをis_prime[i]が示す
    # 最初はすべてTrueで初期化しておく
    # 最終的にprimesではなくこれを返してもよい
    is_prime = array.array("B", (True for i in range(end)))
    # 0, 1はいずれも素数ではない
    is_prime[0] = False
    is_prime[1] = False
    # 素数を格納する配列
    primes = array.array(typecode)
    # 篩う
    for i in range(2, end):
        if is_prime[i]:  # iが素数であるとき
            primes.append(i)  # 素数の配列に加える
            for j in range(2 * i, end, i):  # iを超えるiの倍数について
                is_prime[j] = False  # 素数ではないため除外する
    return primes

if __name__ == "__main__":
    main()
0