#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 510000; const long long INF = 1LL << 61; const long long MOD = 1000000007LL; const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct Matrix { vector > val; Matrix(int n, int m, long long x = 0) : val(n, vector(m, x)) {} void init(int n, int m, long long x = 0) { val.assign(n, vector(m, x)); } size_t size() const { return val.size(); } inline vector& operator [] (int i) { return val[i]; } }; Matrix operator * (Matrix A, Matrix B) { Matrix R(A.size(), B[0].size()); for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j) for (int k = 0; k < B.size(); ++k) R[i][j] = (R[i][j] + A[i][k] * B[k][j] % MOD) % MOD; return R; } Matrix modpow(Matrix A, long long n) { Matrix R(A.size(), A.size()); for (int i = 0; i < A.size(); ++i) R[i][i] = 1; while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; } return R; } int main() { ll a, b, n; cin >> a >> b >> n; Matrix m1(2, 2), m2(2, 1); m2[0][0] = 1; m1[0][0] = a; m1[0][1] = b; m1[1][0] = 1; Matrix res = modpow(m1, n - 1) * m2; cout << res[0][0] << endl; return 0; }