def main(): a, b, n = map(int, input().split()) X = [0] * (n + 1) X[0], X[1] = 0, 1 for i in range(n - 1): X[i + 2] = (a * X[i + 1] + b * X[i]) % (10 ** 9 + 7) print(X[n]) if __name__ == "__main__": main()