# 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.even? hoge((a*a).map{|x|x%M},n/2) else (hoge((a*a).map{|x|x%M},n/2)*a).map{|x|x%M} end end p hoge(mat,N)[1,1]%M