class A def initialize w, d = gets.chomp.split(' ').map(&:to_i) d = [Math.sqrt(w).floor, d].min.to_i d.downto(2) do |day| w -= (w / (day * day).to_f).floor end puts w end end A.new