import numpy as np MOD = 10 ** 9 + 7 def pow(A, n): if n == 0: return np.eye(len(A)) if n == 1: return A % MOD elif n % 2 == 0: return pow(np.dot(A, A) % MOD, n // 2) else: return np.dot(A, pow(A, n - 1)) % MOD def calc(a, b, n): """ x_n を計算する """ A = np.array([ [a, b], [1, 0] ], dtype="uint64") s = np.array([ [1], [0] ], dtype="uint64") if n == 0: return 0 elif n == 1: return 1 else: sq = pow(A, n - 1) return np.dot(sq, s)[0][0] if __name__ == "__main__": input_line = input().split(" ") print(calc(int(input_line[0]), int(input_line[1]), int(input_line[2])))