#include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; ll mpow(ll x, ll n){ //x^n(mod M) ll ans = 1; while(n != 0){ if(n&1) ans = ans*x % MOD; x = x*x % MOD; n = n >> 1; } return ans; } ll minv(ll x){ return mpow( x, MOD-2 ); } void mtxprd( int p, int q, int r, const ll* A, const ll* B, ll* C ) { int i, j, k; for(i=0; i mtx0(dim*dim); vector mtxtmp(dim*dim); mtxcpy( dim, mtx, &mtx0[0] ); mtxuni( dim, mtx2 ); while(n != 0){ if(n&1) { mtxprd( dim, dim, dim, mtx2, &mtx0[0], &mtxtmp[0] ); mtxcpy( dim, &mtxtmp[0], mtx2 ); } mtxprd( dim, dim, dim, &mtx0[0], &mtx0[0], &mtxtmp[0] ); mtxcpy( dim, &mtxtmp[0], &mtx0[0] ); n = n >> 1; } return; } int main(int argc, char* argv[]) { int a,b,n; scanf("%d%d%d", &a, &b, &n); ll A[2*2] = {a, b, 1, 0}; ll B[2*2]; mtxpow( 2, A, n, B); ll x0[2]={1,0}; ll x1[2]; mtxprd( 2, 2, 1, B, x0, x1 ); printf("%lld\n", x1[1]); return 0; }