#include using namespace std; typedef long long ll; const ll MOD = 1000000007; void prod(ll a[2][2], ll b[2][2], ll ans[2][2]){ for(int i = 0; i < 2; i++){ for(int j = 0; j < 2; j++){ ans[i][j] = 0; for(int k = 0; k < 2; k++){ ans[i][j] += a[i][k]*b[k][j]; ans[i][j] %= MOD; } } } } void copy(ll a[2][2], ll b[2][2]){ for(int i = 0; i < 2; i++){ for(int j = 0; j < 2; j++){ b[i][j] = a[i][j]; } } } void pow(ll a[2][2], ll n, ll ans[2][2]){ ll buf[2][2]; ll tmp[2][2]; copy(a, tmp); ans[0][0] = 1; ans[1][1] = 1; ans[0][1] = 0; ans[1][0] = 0; for(int i = 0; i <= 30; i++){ ll m = (ll)1 << i; if(m&n){ prod(tmp, ans, buf); copy(buf, ans); } prod(tmp, tmp, buf); copy(buf, tmp); } } int main(){ ll a, b, n; cin >> a >> b >> n; ll s[2][2]; ll ans[2][2]; s[0][0] = a; s[0][1] = b; s[1][0] = 1; s[1][1] = 0; pow(s, n, ans); cout << ans[1][0] << endl; }