#include #include using namespace std; using mint = atcoder::modint1000000007; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } using vec = vector; using mat = vector; mat mul(const mat& a, const mat& b) { int n = a.size(); int m = b.size(); int k = b[0].size(); mat c(n, vec(k)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int l = 0; l < k; l++) { c[i][l] += a[i][j] * b[j][l]; } } } return c; } mat pow(mat a, long long n) { int m = a.size(); mat res(m, vec(m)); for (int i = 0; i < m; i++) { res[i][i] = 1; } while (n > 0) { if (n & 1) { res = mul(res, a); } a = mul(a, a); n >>= 1; } return res; } int main() { fast_io(); int a, b, n; cin >> a >> b >> n; if (n == 0) { cout << 0 << endl; return 0; } mat A = {{a, b}, {1, 0}}; auto B = pow(A, n - 1); cout << B[0][0].val() << '\n'; }