#include using namespace std; #define rep(i, m, n) for (int i = m; i < n; ++i) const long long MOD = 1000000007; using vec = vector; using Mat = vector; Mat Mul(Mat A, Mat B) { Mat C(A.size(), vec(B[0].size())); rep(i, 0, A.size()) rep(k, 0, B.size()) rep(j, 0, B[0].size()) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD; } return C; } Mat Pow(Mat A, long long n) { int SZ = A.size(); Mat B(SZ, vec(SZ)); rep(i, 0, SZ) B[i][i] = 1; while(n > 0) { if(n & 1) B = Mul(B, A); A = Mul(A, A); n >>= 1; } return B; } int main() { long long a, b, n; cin >> a >> b >> n; Mat A(2, vec(2)); A[0][0] = a; A[0][1] = b; A[1][0] = 1LL; A[1][1] = 0LL; A = Pow(A, n); cout << A[1][0] << endl; return 0; }