require 'matrix' a,b,n=gets.split.map(&:to_i) mod = 1e9+7 def rui(m,x) if x==1 m else if x.even? rui(m,x/2)*rui(m,x/2) else rui(m,x-1)*m end end end ma = Matrix[[a, b], [1, 0]] p (rui(ma,n)*Matrix[[1],[0]])[1,0]%mod.ceil # .tap{|e|p e[0,1]}