gets a = gets.split.map(&:to_r) gets b = gets.split.map(&:to_r) x = a.inject(:/) / b.reverse.inject{|x, y| y / x} puts "#{x.numerator} #{x.denominator}"