結果

問題 No.3253 Banned Product
ユーザー norioc
提出日時 2025-09-08 21:40:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 960 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,840 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2025-09-08 21:40:55
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(n: int) -> list[int]:
    """n の約数を求める"""
    s = set()
    p = 1
    while p * p <= n:
        if n % p == 0:
            s.add(p)
            s.add(n // p)
        p += 1
    return sorted(s)


def solve():
    N, K = map(int, input().split())

    for x in reversed(range(max(1, N-281), N+1)):
        if x <= K: break
        ds = divisors(x)
        ok = True
        for d in ds:
            a = d
            b = x // d
            if a <= K and b <= K:
                ok = False
                break

        if ok:
            return x
        elif len(ds) == 2:  # priem
            break

    return -1


T = int(input())
for _ in range(T):
    ans = solve()
    print(ans)
0