require 'prime' L, H = gets.split.map(&:to_i) primes = Prime.each(Math.sqrt(H)).to_a.reverse primes.each do |x| y = H / x n = y * x while n >= L if n.prime_division[0][0] >= x puts n exit end n -= x end end