結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kjnhokjnho
提出日時 2016-05-16 22:38:07
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,683 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 31,532 KB
最終ジャッジ日時 2024-04-15 22:39:17
合計ジャッジ時間 4,984 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 82 ms
11,816 KB
testcase_03 AC 80 ms
11,816 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 83 ms
11,816 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 82 ms
11,816 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 81 ms
11,896 KB
testcase_13 AC 87 ms
11,816 KB
testcase_14 AC 84 ms
11,820 KB
testcase_15 WA -
testcase_16 AC 83 ms
11,820 KB
testcase_17 AC 83 ms
11,816 KB
testcase_18 WA -
testcase_19 AC 81 ms
11,948 KB
testcase_20 WA -
testcase_21 AC 184 ms
11,816 KB
testcase_22 WA -
testcase_23 AC 167 ms
11,676 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:
        print("in")
        P = max(cands)
        PP = P * min(p for p in primes if p > P)
        if PP <= H:
            print(PP)
        else:
            print(P*P)

    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