#include using namespace std; class mixed { public: long re, im; }; mixed mul(mixed, mixed); const long m = 1000000007; long det; int main() { long a, b, n; cin >> a >> b >> n; long ahalf = a % 2 == 0 ? a / 2 : (a + m) / 2; det = (ahalf * ahalf % m + b) % m; mixed alpha, x, cache; alpha.re = ahalf; alpha.im = 1; x.re = 1; x.im = 0; cache = alpha; while (n > 0) { if (n % 2 == 1) { x = mul(x, cache); } cache = mul(cache, cache); n /= 2; } cout << x.im << endl; } mixed mul(mixed x, mixed y) { mixed z; z.re = (x.re * y.re % m + det * (x.im * y.im % m) % m) % m; z.im = (x.re * y.im % m + x.im * y.re % m) % m; return z; }