#include using namespace std; const long long int MOD = 1e9 + 7; vector > mul(vector > a, vector> b) { vector >c(2, vector(2)); c[0][0] = 0; c[0][1] = 0; c[1][0] = 0; c[1][1] = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { c[i][j] += (a[i][k] * b[k][j]); c[i][j] %= MOD; } } } return c; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); vector > a(2, vector(2)); vector > b(2, vector(2)); long long int n, A, B; cin >> A >> B >> n; a[0][0] = A; a[0][1] = B; a[1][0] = 1; a[1][1] = 0; b[0][0] = 1; b[0][1] = 0; b[1][0] = 0; b[1][1] = 1; while (n > 0) { if (n & 1) { b = mul(a, b); } a = mul(a, a); n >>= 1; } cout << b[1][0] << '\n'; return 0; }