結果

問題 No.3253 Banned Product
ユーザー Tatsu_mr
提出日時 2025-09-06 00:17:41
言語 Ruby
(3.4.1)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 8,064 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2025-09-06 00:17:44
合計ジャッジ時間 2,516 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def is_prime(x)
    if x == 1 then
        return false
    end
    if x == 2 then
        return true
    end
    a = 2
    while a * a <= x
        if x % a == 0 then
            return false
        end
        a += 1
    end
    return true
end

def is_good(x, k)
    a = 1
    while a * a <= x && a <= k
        if x % a == 0 then
            b = x / a
            if b <= k then
                return false
            end
        end
        a += 1
    end
    return true
end

t = gets.to_i
t.times do
    n, k = gets.split.map(&:to_i)
    ans = -1
    n.downto(1) do |x|
        if is_good(x, k) then
            ans = x
            break
        end
        if is_prime(x) then
            break
        end
    end
    puts ans
end
0