MOD=10**9+7 def matmul(A,B,mod): # A,B: 行列 res = [[0]*len(B[0]) for _ in [None]*len(A)] for i, resi in enumerate(res): for k, aik in enumerate(A[i]): for j,bkj in enumerate(B[k]): resi[j] += aik*bkj resi[j] %= mod return res def matpow(A,p,M): #A^p mod M if p%2: return matmul(A, matpow(A,p-1,M), M) elif p > 0: b = matpow(A,p//2,M) return matmul(b,b,M) else: return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))] a,b,n = [int(i) for i in input().split()] A = [[0,b],[1,a]] ans = matpow(A,n,MOD) print(ans[0][1])