#include using namespace std; const int MOD = 1e9 + 7; vector> mmul(vector> a, vector> b) { vector> c(a.size(), vector(b[0].size())); for (int i = 0; i < a.size(); ++i) { for (int j = 0; j < b.size(); ++j) { for (int k = 0; k < b[0].size(); ++k) { (c[i][k] += 1LL * a[i][j] * b[j][k] % MOD) %= MOD; } } } return c; } vector> mpow(vector> a, int n) { vector> r(a.size(), vector(a.size())); for (int i = 0; i < a.size(); ++i) r[i][i] = 1; for (int i = n; i; i >>= 1) { if (i & 1) r = mmul(r, a); a = mmul(a, a); } return r; } int main() { int A, B, N; cin >> A >> B >> N; vector> t({ { A, B }, { 1, 0 } }); vector> a0({ { 1 }, { 0 } }); int an = mmul(mpow(t, N), a0)[1][0]; cout << an << endl; return 0; }