-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU {- 解説読後 http://yukicoder.me/problems/875/editorial 何人かの他の人のACコードを読んでみて解説の意味を理解した -} main = print . solve . map read . words =<< getLine solve (n:m:_) = g rd dif 0 where f = take n fib rf = reverse f rd = drop 2 rf fn = head rf dif = fn - m g [] d p = if d == 0 then p else (-1) g (x:xs) d p | x > d = g xs d p | otherwise = g xs (d - x) (p + 1) fib = [1, 1] ++ [(a + b) | x <- [0..], let (a:b:_) = drop x fib]