#include #include #include #include int ri() { int n; scanf("%d", &n); return n; } #define MOD 1000000007 int main() { int a, b, n; scanf("%d%d%d", &a, &b, &n); assert(0 <= a && a < MOD); assert(0 <= b && b < MOD); assert(0 <= n && n < MOD); int x[2][2] = {{0, 1}, {b, a}}; int v[2] = {0, 1}; for (; n; n >>= 1) { if (n & 1) { int t1 = ((int64_t) v[0] * x[0][0] + (int64_t) v[1] * x[0][1]) % MOD; int t2 = ((int64_t) v[0] * x[1][0] + (int64_t) v[1] * x[1][1]) % MOD; v[0] = t1, v[1] = t2; } int new_x[2][2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) new_x[i][j] = ((int64_t) x[i][0] * x[0][j] + (int64_t) x[i][1] * x[1][j]) % MOD; memcpy(x, new_x, sizeof(new_x)); } printf("%d\n", v[0]); return 0; }