import numpy as np #A**n def mat_pow(A, n, mod): size = len(A) res = np.eye(size, dtype=np.object) while n > 0: if n & 1 == 1: res = res @ A res %= mod A = A @ A A %= mod n = n>>1 return res # https://yukicoder.me/problems/no/891 a, b, n = map(int, input().split()) x = np.array([[1], [0]]) mod = 10**9+7 if n <= 1: print(x[1-n][0]%mod) exit() A = np.array([[a, b], [1, 0]]) A = mat_pow(A, n-1, mod) print((A@x)[0][0])