#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MP make_pair #define PB push_back #define inf 1000000007 #define mod 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) template class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr bool operator==(const modint rhs) noexcept{ return (*this).value()==rhs.value(); } inline constexpr bool operator!=(const modint rhs) noexcept{ return !(*this==rhs); } }; int main(){ int aa,bb,n; cin >> aa >> bb >> n; modint p[2][2]={}; p[0][0] = aa; p[0][1] = bb; p[1][0] = 1; p[1][1] = 0; modint res[2][2]={}; res[0][0] = 1; res[1][1] = 1; while(n){ if(n & 1){ modint res2[2][2]={}; rep(i,2){ rep(j,2){ rep(k,2){ res2[i][j] += res[i][k]*p[k][j]; } } } rep(i,2){ rep(j,2){ res[i][j] = res2[i][j]; } } } modint res2[2][2]={}; rep(i,2){ rep(j,2){ rep(k,2){ res2[i][j] += p[i][k]*p[k][j]; } } } rep(i,2){ rep(j,2){ p[i][j] = res2[i][j]; } } n >>= 1; } modint ans=res[1][0]; cout << ans.value() << endl; return 0; }