#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; template struct Matrix{ int h,w; vector a; Matrix(int n_=0):h(n_),w(n_),a(n_*n_){} Matrix(int n_, int m_):h(n_),w(m_),a(n_*m_){} Matrix(int n_, int m_, vector a_):h(n_),w(m_),a(a_){} T& get(int r,int c){return a[r*w+c];} T get(int r,int c)const{return a[r*w+c];} Matrix& operator+=(const Matrix& m) { assert(h == m.h && w == m.w); for (int i = 0; i < w*h; ++i)a[i] += m.a[i]; } Matrix& operator-=(const Matrix& m) { assert(h == m.h && w == m.w); for (int i = 0; i < w*h; ++i)a[i] -= m.a[i]; } Matrix& operator*=(const Matrix& m) { assert(w == m.h); Matrix ret(h, m.w); for (int i = 0; i < h; ++i) { for (int j = 0; j < m.w; ++j) { for (int k = 0; k < w; ++k) { ret.a[i * m.w + j] += a[i * w + k] * m.a[k * m.w + j] %mod; } ret.a[i * m.w + j] %= mod; } } return (*this) = ret; } Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; } Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; } Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; } }; template Matrix unit(int n){ Matrix ret(n); rep(i,n)ret.get(i,i)=1; return ret; } template Matrix matpow(Matrix a,int n){ assert(a.h==a.w); Matrix ret=unit(a.h); while(n){ if(n&1)ret*=a; a*=a; n>>=1; } return ret; } int main(){ ll a,b,n; cin>>a>>b>>n; Matrix mat(2); mat.get(0,0)=a; mat.get(0,1)=b; mat.get(1,0)=1; --n; auto ret = matpow(mat,n); cout<