def main(): try: import pypyjit pypyjit.set_param('max_unroll_recursion=-1') except: pass try: import sys sys.setrecursionlimit(10**7) except: pass from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum from heapq import heapify, heappop, heappush from bisect import bisect_left, bisect_right from copy import deepcopy import copy import random from collections import deque,Counter,defaultdict from itertools import permutations,combinations from decimal import Decimal,ROUND_HALF_UP #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP) from functools import lru_cache, reduce #@lru_cache(maxsize=None) from operator import add,sub,mul,xor,and_,or_,itemgetter INF = 10**18 mod1 = 10**9+7 mod2 = 998244353 #DecimalならPython ''' 自明解は避ける ''' def matmul(a, b, mod): m = len(a) l = len(a[0]) n = len(b[0]) ret = [[0] * n for _ in range(m)] for i in range(m): for j in range(n): e = 0 for k in range(l): e = (e + a[i][k] * b[k][j]) % mod ret[i][j] = e return ret def matpow(X, exp, mod): Y = [[int(i == j) for j in range(len(X))] for i in range(len(X))] while exp > 0: if exp & 1: Y = matmul(X, Y, mod) X = matmul(X, X, mod) exp >>= 1 return Y a,b,n = map(int, input().split()) A = [[a,b],[1,0]] B = matpow(A,n-1,mod1) print(B[0][0]) if __name__ == '__main__': main()