結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-22 09:57:03
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 1,064 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 9,332 KB
最終ジャッジ日時 2023-08-29 01:12:13
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,968 KB
testcase_01 AC 16 ms
7,768 KB
testcase_02 AC 17 ms
7,868 KB
testcase_03 AC 17 ms
7,836 KB
testcase_04 AC 16 ms
7,924 KB
testcase_05 AC 16 ms
7,856 KB
testcase_06 AC 16 ms
7,832 KB
testcase_07 AC 16 ms
7,976 KB
testcase_08 AC 16 ms
7,872 KB
testcase_09 AC 16 ms
7,860 KB
testcase_10 AC 16 ms
7,764 KB
testcase_11 AC 16 ms
7,840 KB
testcase_12 AC 16 ms
7,888 KB
testcase_13 AC 16 ms
7,888 KB
testcase_14 AC 16 ms
7,972 KB
testcase_15 AC 16 ms
7,824 KB
testcase_16 AC 16 ms
7,844 KB
testcase_17 AC 16 ms
7,868 KB
testcase_18 AC 16 ms
7,804 KB
testcase_19 AC 17 ms
7,844 KB
testcase_20 AC 16 ms
7,836 KB
testcase_21 AC 16 ms
7,860 KB
testcase_22 AC 17 ms
8,436 KB
testcase_23 AC 17 ms
8,568 KB
testcase_24 AC 21 ms
9,232 KB
testcase_25 AC 21 ms
9,296 KB
testcase_26 AC 25 ms
9,204 KB
testcase_27 AC 21 ms
9,140 KB
testcase_28 AC 21 ms
9,240 KB
testcase_29 AC 20 ms
9,208 KB
testcase_30 AC 21 ms
9,212 KB
testcase_31 AC 21 ms
9,120 KB
testcase_32 AC 20 ms
9,112 KB
testcase_33 AC 20 ms
9,240 KB
testcase_34 AC 21 ms
9,208 KB
testcase_35 AC 20 ms
9,220 KB
testcase_36 AC 19 ms
8,804 KB
testcase_37 AC 20 ms
9,332 KB
testcase_38 AC 20 ms
9,272 KB
testcase_39 AC 20 ms
9,220 KB
testcase_40 AC 21 ms
9,280 KB
testcase_41 AC 20 ms
9,176 KB
testcase_42 AC 20 ms
9,092 KB
testcase_43 AC 21 ms
9,188 KB
testcase_44 AC 21 ms
8,992 KB
testcase_45 AC 17 ms
7,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes2(limit):
    ''' returns a list of prime numbers upto limit.
    source: Rossetta code: Sieve of Eratosthenes
    http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above
    '''
    if limit < 2: return []
    if limit < 3: return [2]
    lmtbf = (limit - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(limit ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return [2] + [i + i + 3 for i, v in enumerate(buf) if v]


def solve(L, H):
    maxp = int(H**0.5)
    ps = primes2(maxp)
    for p in ps[::-1]:
        pp = find_pseudo_prime(p, L, H, ps)
        if pp:
            return pp

def find_pseudo_prime(p, L, H, ps):
    lower = L//p + (1 if L%p else 0)
    for q in range(H//p, lower - 1, -1):
        for r in ps:
            if r >= p:
                return p * q
            if q % r == 0:
                break
    return 0

L, H = map(int, input().split())
print(solve(L, H))
0