class A def initialize w = gets.chomp.to_i d = gets.chomp.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