import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 # md = 998244353 md = 10**9+7 # af(n)+bf(n+1)+cf(n+2)+df(n+3)=f(n+4)みたいなとき # coeff=[a,b,c,d] # 初期値f0(f(0)からf(3)) class Fibonacci: def __init__(self, coeff, f0): self.f0 = f0 n = len(coeff) ff = [[0]*n for _ in range(2*n-1)] for i in range(n): ff[i][i] = 1 for i in range(n, 2*n-1): ffi = ff[i] for j, c in enumerate(coeff, i-n): ffj = ff[j] for k in range(n): ffi[k] += c*ffj[k] self.bn = 1 << (n-1).bit_length() self.base = ff[self.bn] self.ff = ff self.n = n def __mm(self, aa, bb): n = self.n res = [0]*(n*2-1) for i, a in enumerate(aa): for j, b in enumerate(bb): res[i+j] += a*b res[i+j] %= md for i in range(n, 2*n-1): c = res[i] ffi = self.ff[i] for j in range(n): res[j] += c*ffi[j] res[j] %= md return res[:n] def v(self, x): base = self.base aa = self.ff[x%self.bn] x //= self.bn while x: if x & 1: aa = self.__mm(aa, base) base = self.__mm(base, base) x >>= 1 return sum(a*f%md for a, f in zip(aa, self.f0))%md a, b, n = MI() if a == b == 0: if n==1:print(1) else:print(0) elif b == 0: if n==0:print(0) else:print(pow(a, n-1, md)) else: fibo = Fibonacci([b, a], [0, 1]) print(fibo.v(n))