import numpy as np A, B, N = map(int, input().split()) MOD = 10 ** 9 + 7 def pow_matrix_mod(x, n, mod=MOD): x = x.astype(object) if not n: return np.eye(len(x), dtype=object) if n % 2 == 0: return pow_matrix_mod(x @ x % mod, n // 2) % mod else: return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod if A == 0 and B == 0: ans = 1 if N == 1 else 0 elif A == 0: ans = pow(B, N // 2, MOD) if N % 2 else 0 elif B == 0: ans = pow(A, N - 1, MOD) if N else 0 else: X = np.array([[0, 1], [B, A]], dtype=int) ans = pow_matrix_mod(X, N)[0, 1] print(ans)