#include #include using namespace std; typedef vector> Matrix; // 行列の乗算(mod) Matrix ModMultiMatrix(const Matrix &a, const Matrix &b, int64_t mod) { Matrix c(a.size(), vector(b.at(0).size())); for(int i = 0; i < a.size(); i++) { for(int j = 0; j < b.size(); j++) { for(int k = 0; k < b.at(0).size(); k++) { c.at(i).at(k) += a.at(i).at(j) * b.at(j).at(k); c.at(i).at(k) %= mod; } } } return c; } // 行列の累乗(mod) Matrix ModPowerMatrix(Matrix a, int64_t n, int64_t mod) { Matrix b(a.size(), vector(a.size())); for(int i = 0; i < a.size(); i++) b.at(i).at(i) = 1; while(n > 0) { if(n & 1) b = ModMultiMatrix(b, a, mod); a = ModMultiMatrix(a, a, mod); n >>= 1; } return b; } int main() { int64_t A, B, N; cin >> A >> B >> N; if(N == 0) { cout << 0 << endl; return 0; } int64_t mod = 1000000007; Matrix mat(2, vector(2)); mat.at(0).at(0) = A; mat.at(0).at(1) = B; mat.at(1).at(0) = 1; mat = ModPowerMatrix(mat, N - 1, mod); Matrix F(2, vector(1)); F.at(0).at(0) = 1; Matrix ans = ModMultiMatrix(mat, F, mod); cout << ans.at(0).at(0) << endl; return 0; }