import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a,b,n = map(int,read().split()) MOD = 10 ** 9 + 7 # x^n = p + qx mod x^2 - ax - b def power(n): if n == 0: return 1,0 p,q = power(n//2) p,q,r = p*p,2*p*q,q*q q += a * r; p += b * r p %= MOD q %= MOD if not n&1: return p,q p,q,r = 0,p,q q += a * r; p += b * r p %= MOD q %= MOD return p,q p,q = power(n) print(q)