#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #include #include #include //< in.txt > out.txt using namespace std; //std::ios::sync_with_stdio(false); //std::cin.tie(0); const long long MOD = 1e9 + 7; typedef long long LL; typedef long double LD; typedef pair PLL; typedef pair PDL; typedef pair PDD; typedef vector VLL; typedef vector VVLL; //typedef boost::multiprecision::cpp_int bigint; template void in(T& x) { cin >> x; } template void in(pair& p) { in(p.first); in(p.second); } template void in(vector& v, LL st = -1, LL en = -1) { if (st == -1) { st = 0; en = v.size() - 1; } for (LL n = st; n <= en; n++) { in(v[n]); } } VVLL modpow(VVLL base, LL p) { if (p == 0) { VVLL res; res.resize(2, VLL(2, 0)); res[0][0] = 1; res[1][1] = 1; return res; } if (p == 1) return base; VVLL res = modpow(base, p / 2); VVLL temp; temp.resize(2, VLL(2,0)); for (LL x = 0; x < 2; x++) { for (LL y = 0; y < 2; y++) { for (LL k = 0; k < 2; k++) { temp[x][y] += res[x][k] * res[k][y]; temp[x][y] %= MOD; } } } if (p % 2 == 0)return temp; VVLL temp2; temp2.resize(2, VLL(2, 0)); for (LL x = 0; x < 2; x++) { for (LL y = 0; y < 2; y++) { for (LL k = 0; k < 2; k++) { temp2[x][y] += temp[x][k] * base[k][y]; temp2[x][y] %= MOD; } } } return temp2; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); LL a, b, n; cin >> a >> b >> n; if (n == 0) { cout << 0 << "\n"; return 0; } else if (n == 1) { cout << 1 << "\n"; return 0; } VVLL base; base.resize(2, VLL(2, 0)); base[0][0] = a; base[0][1] = b; base[1][0] = 1; base = modpow(base, n - 1); cout << (base[0][0] + MOD) % MOD << "\n"; return 0; }