#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long mod = 1000000007; int main() { long long a, b, n; cin >> a >> b >> n; if (n <= 1) { cout << n << endl; return 0; } long long x1 = 1, x2 = 0, x3 = 0, x4 = 1; long long y1, y2, y3, y4; long long a1 = a, a2 = b, a3 = 1, a4 = 0; while (n > 0) { if (n % 2 == 1) { y1 = (a1 * x1 + a2 * x3) % mod; y2 = (a1 * x2 + a2 * x4) % mod; y3 = (a3 * x1 + a4 * x3) % mod; y4 = (a3 * x2 + a4 * x4) % mod; x1 = y1; x2 = y2; x3 = y3; x4 = y4; } { y1 = (a1 * a1 + a2 * a3) % mod; y2 = (a1 * a2 + a2 * a4) % mod; y3 = (a3 * a1 + a4 * a3) % mod; y4 = (a3 * a2 + a4 * a4) % mod; a1 = y1; a2 = y2; a3 = y3; a4 = y4; } n /= 2; } cout << x3 << endl; return 0; }