#include #include using mint = atcoder::modint1000000007; struct Divisor_n { std::vector> prime_factor; int pow(int n, int k) { int res = 1; while (k--) res *= n; return res; } public: Divisor_n(int n) { for (int i = 2; i * i <= n; i++) { if (n % i) continue; prime_factor.emplace_back(i, 0); while (n % i == 0) { prime_factor.back().second++; n /= i; } } if (n > 1) prime_factor.emplace_back(n, 1); } std::vector divisors() { int prod = 1; for (const auto &[p, e] : prime_factor) prod *= e + 1; std::vector res; for (int S : std::views::iota(0, prod)) { int x = 1; for (const auto &[p, e] : prime_factor) { x *= pow(p, S % (e + 1)); S /= e + 1; } res.push_back(x); } return res; } int phi(int d) { int res = d; for (const int p : prime_factor | std::views::elements<0>) if (d % p == 0) (res /= p) *= p - 1; return res; } }; using ll = long long; int main() { int h, w, k; std::cin >> h >> w >> k; Divisor_n H(h), W(w); mint ans = 0; for (int x : H.divisors()) for (int y : W.divisors()) ans += mint::raw(k).pow(h * ll(w) / std::lcm(x, y)) * H.phi(x) * W.phi(y); std::cout << (ans / (h * mint::raw(w))).val() << std::endl; }