#!/usr/bin/env python3 import numpy M = 10 ** 9 + 7 def mat_mul_mod(x, y, mod=M): return x @ y % mod def mat_pow_mod(x, n, mod=M): y = numpy.array([[1, 0], [0, 1]], dtype=numpy.int64) while n > 0: if n % 2 == 1: y = mat_mul_mod(y, x, mod) x = mat_mul_mod(x, x, mod) n >>= 1 return y def solve(a, b, n, mod=M): x = numpy.array([[a, b], [1, 0]], dtype=numpy.int64) res = mat_pow_mod(x, n) z = numpy.array([[1, ], [0, ]], dtype=numpy.int64) res = mat_mul_mod(res, z, mod) return res[1, 0] def main(): a, b, n = (int(z) for z in input().split()) ans = solve(a, b, n) print(ans) if __name__ == "__main__": main()