結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kjnhokjnho
提出日時 2016-05-16 21:53:41
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,840 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 33,284 KB
最終ジャッジ日時 2024-04-15 22:38:45
合計ジャッジ時間 3,776 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
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(int(math.ceil(root_H)))
    square_primes = [x**2 for x in primes]
    print(primes)

    cands = [p for p in primes if L <= p**2 <= H]
    if cands:
        P = max(cands)

        flag = True; n = H
        while flag:
            for p in primes:
                if n%p == 0 and n!= p:
                    print(n)
                    flag = False
                    break
                n -= 1

    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