#include using namespace std; using Int = long long; const int mod = 1e9 + 7; #define fast() cin.tie(0), ios::sync_with_stdio(false) const Int MOD = 1e9 + 7; //<- alert!!! typedef vector arr; typedef vector mat; inline arr mul(const mat &a, arr &b, Int mod) { arr res(b.size(), 0); for (Int i = 0; i < (Int)b.size(); i++) for (Int j = 0; j < (Int)a[i].size(); j++) (res[i] += a[i][j] * b[j]) %= mod; return res; } inline mat mul(const mat &a, const mat &b, Int mod) { mat res(a.size(), arr(b[0].size(), 0)); for (Int i = 0; i < (Int)a.size(); i++) for (Int j = 0; j < (Int)b[0].size(); j++) for (Int k = 0; k < (Int)b.size(); k++) (res[i][j] += a[i][k] * b[k][j]) %= mod; return res; } inline mat mat_pow(mat a, Int n, Int mod) { mat res(a); for (Int i = 0; i < (Int)a.size(); i++) for (Int j = 0; j < (Int)a[i].size(); j++) res[i][j] = (i == j); while (n) { if (n & 1) res = mul(a, res, mod); a = mul(a, a, mod); n >>= 1; } return res; } Int fib(Int a, Int b, Int n) { mat A(2, arr(2)); A[0][0] = a, A[0][1] = b, A[1][0] = 1, A[1][1] = 0; A = mat_pow(A, n, MOD); return A[1][0]; } Int a, b, N; int main() { cin >> a >> b >> N; if (N == 0) { cout << 0 << endl; return 0; } else if (N == 1) { cout << 1 << endl; return 0; } Int ans = fib(a, b, N); cout << ans << endl; }