mod = 10 ** 9 + 7 def matrix_multiplication(a, b): n = len(a) res = [[0] * n for i in range(n)] for i in range(n): for k in range(n): for j in range(n): res[i][j] += a[i][k] * b[k][j] res[i][j] %= mod return res def matrix_pow(a, k): n = len(a) res = [[0] * n for i in range(n)] for i in range(n): res[i][i] = 1 while k: if k & 1: res = matrix_multiplication(res, a) a = matrix_multiplication(a, a) k >>= 1 return res a, b, n = map(int, input().split()) if n == 0:exit(print(0)) if n == 1:exit(print(1)) M = [[a, b], [1, 0]] print(matrix_pow(M, n - 1)[0][0])