#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef long long ll; typedef pair pii; typedef pair pll; const ll INF = 1ll<<30; const ll longINF = 1ll<<60; const ll MOD = 1000000007; const double EPS = 1e-9; const bool debug = 0; //---------------------------------// typedef vector vl; typedef vector vvl; vvl multi(vvl &a, vvl &b, ll mod) { vvl res(a.size(), vl(b[0].size())); REP(i, a.size()) { REP(j, b[0].size()) { REP(k, b.size()) { res[i][j] += a[i][k] * b[k][j] % mod; res[i][j] %= mod; } } } return res; } vvl pow(vvl x, ll n, ll mod) { vvl res(x.size(), vl(x.size())); REP(i, x.size()) res[i][i] = 1; while (n > 0) { if (n & 1) res = multi(res, x, mod); x = multi(x, x, mod); n >>= 1; } return res; } vvl init(ll a, ll b) { vvl res(2, vl(2)); res[0][0] = a; res[0][1] = b; res[1][0] = 1; res[1][1] = 0; return res; } ll solve(ll x, ll mod, ll a, ll b) { vvl cur = init(a, b); vvl se(2, vl(1)); se[0][0] = 1; se[1][0] = 0; cur = pow(cur, x - 1, mod); cur = multi(cur, se, mod); return cur[0][0]; } int main() { ll a, b, n; cin >> a >> b >> n; cout << solve(n, MOD, a, b) << endl; return 0; }