# yukicoder My Practice # author: Leonardone @ NEETSDKASU require 'matrix' N, M = gets.strip.split.map &:to_i mat = Matrix[[1, 1], [1, 0]] def hoge(a, n) if n == 1 a elsif n == 2 (a * a).map{|x|x%M} elsif n.even? b = hoge(a, n / 2) (b * b).map{|x|x%M} else (hoge(a,n/2)*hoge(a,(n+1)/2)).map{|x|x%M} end end p hoge(mat, N)[1,1]%M