#include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(int i = 0; i < (int)(n); ++i) using namespace std; constexpr int mod = 1000000007; using mat = vector>; mat matrix_mul(mat A, mat B) { mat C(A.size(), vector(B[0].size(), 0)); rep(i, A.size()) rep(j, B[0].size()) rep(k, B.size()) { C[i][j] += (long long)A[i][k] * B[k][j] % mod; C[i][j] %= mod; } return C; } mat matrix_pow(mat A, int n) { if (n == 1) return A; mat B = matrix_pow(A, n / 2); if (n % 2) return matrix_mul(matrix_mul(B, B), A); return matrix_mul(B, B); } int main() { int a, b, n; cin >> a >> b >> n; mat A = {{a, b}, {1, 0}}; mat B = {{1}, {0}}; mat ans = matrix_mul(matrix_pow(A, n), B); cout << ans[1][0] << endl; return 0; }