def ascan; gets.split.map(&:to_i);end require 'prime' L, H = ascan sqrtH = Math.sqrt(H).to_i ans = [0,0] sqrtH.downto(2) do |x| next unless x.prime? ## 篩を使えばこの計算量をループの外に出せる y = H / x yfact = y.prime_division.map(&:shift).min ## niceな実装ならO(sqrt(N)) next if x * y < L curr = [ [x,yfact].min, x*y ] ans = [curr, ans].max end p ans[1]