class Yukicoder def initialize n, m = gets.chomp.split.map(&:to_i) fibo = Array.new(n+1, 0) fibo[1] = 1 fibo[2] = 1 3.upto(3+n) do |i| fibo[i] = fibo[i-1] + fibo[i-2] end diff = fibo[n] - m if diff < 0 puts -1 else answer = 0 index = n while diff > 0 && index > 0 if fibo[index] <= diff answer += 1 diff -= fibo[index] end index -= 1 end if diff == 0 puts answer else puts -1 end end end end Yukicoder.new