MOD = 10**9 + 7 def matrix_mult(a, b): res = [[0] * 2 for _ in range(2)] for i in range(2): for j in range(2): res[i][j] = (a[i][0] * b[0][j] + a[i][1] * b[1][j]) % MOD return res def matrix_power(mat, exponent): result = [[1, 0], [0, 1]] # Identity matrix current = [row[:] for row in mat] while exponent > 0: if exponent % 2 == 1: result = matrix_mult(result, current) current = matrix_mult(current, current) exponent //= 2 return result a, b, n = map(int, input().split()) if n == 0: print(0) elif n == 1: print(1 % MOD) else: a_mod = a % MOD b_mod = b % MOD mat = [[a_mod, b_mod], [1, 0]] exponent = n - 1 mat_pow = matrix_power(mat, exponent) print(mat_pow[0][0] % MOD)