#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; #define MOD 1000000007 //m次正方行列の積 vector> matrixmul(ll m,vector> a,vector> b){ vector> c(m,vector(m,0)); rep(i,m){ rep(j,m){ rep(k,m) c[i][j]=(c[i][j]+a[i][k]*b[k][j]%MOD)%MOD; } } return c; } //m次正方行列vecのn乗 vector> matrixpow(ll m,vector> vec,ll n){ vector> ans(m,vector(m,0)); rep(i,m) ans[i][i]=1; while(n){ if(n&1) ans=matrixmul(m,ans,vec); vec=matrixmul(m,vec,vec); n>>=1; } return ans; } int main(){ ll a,b,n; cin>>a>>b>>n; vector> A(2,vector (2)),B(2,vector (2)), C(2,vector (2)),D(2,vector (2)); A[0][0]=a,A[0][1]=b,A[1][0]=1LL,A[1][1]=a; B[0][0]=a,B[0][1]=-b,B[1][0]=-1LL,B[1][1]=a; C=matrixpow(2,A,n); D=matrixpow(2,B,n); cout<<(C[0][0]+D[0][0])%MOD<