#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() const ll mod = 1e9 + 7; int main() { cin.tie(nullptr); ll A, B, N; cin >> A >> B >> N; ll ans = 1; vector vec(N, A); while (true) { if (vec[N - 1] == B + 1) break; ll g = vec[0]; rep(i, 1, N) g = gcd(g, vec[i]); ans *= g; ans %= mod; vec[0]++; rep(i, 0, N - 1) { if (vec[i] == B + 1) { vec[i] = A; vec[i + 1]++; } } } cout << ans << '\n'; }