import numpy as np def mat_power(m: np.ndarray, n: int, mod: int) -> np.ndarray: if n == 0: return np.identity(len(m), dtype=object) res = mat_power(m, n // 2, mod) res = res @ res % mod if n % 2 == 1: res = res @ m % mod return res MOD = 10 ** 9 + 7 B, C, D = map(int, input().split()) m = np.array( [[C, B], [0, 1]]) a = np.array( [[B], [1]]) t = mat_power(m, D, MOD) @ a ans = (t[0, 0] - B) % MOD print(ans)