#include using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a,Ts... ts){ return std::vector(ts...))>(a,make_v(ts...)); } struct matrix { std::vector> A; const int MOD = 1e9 + 7; matrix(const int & n) { A.resize(n, std::vector(n)); } matrix operator*(matrix B) { const int n = A.size(); matrix C(n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < n; k++) { (C[i][j] += A[i][k] * B[k][j] % MOD) %= MOD; } } } return C; } void pow(i64 n) { int d = A.size(); matrix ret(d); for(int i = 0; i < d; i++) ret[i][i] = 1; while(n) { if(n & 1) ret = ret * (*this); (*this) = (*this) * (*this); n >>= 1; } (*this) = ret; } void operator=(matrix B) { A.swap(B.A); } std::vector & operator[](const int & i) { return A[i]; } }; int main() { i64 a, b, n; scanf("%lld%lld%lld", &a, &b, &n); if(n == 0) { printf("0\n"); return 0; } if(n == 1) { printf("1\n"); return 0; } matrix A(2); A[0][0] = a; A[0][1] = b; A[1][0] = 1; A[1][1] = 0; A.pow(n - 1); printf("%lld\n", A[0][0]); return 0; }