#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);} ll gcd(ll a, ll b) {return (b==0) ? a : gcd(b, a%b);} ll lcm(ll a, ll b) {return a/gcd(a, b)*b;} /// x^n template T pow(T x, ll n) { T r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template struct ModInt { uint v; ModInt() : v(0) {} ModInt(ll v) : v(normS(v%MD+MD)) {} uint value() const {return v;} static uint normS(const uint &x) {return (x; using P = pair; vector

calc(ll X) { vector v; for (ll i = 1; i*i <= X; i++) { if (X%i == 0) { v.push_back(i); if (i*i != X) { v.push_back(X/i); } } } sort(v.begin(), v.end()); int N = (int)v.size(); vector

ans(N); for (int i = N-1; i >= 0; i--) { ll co = X/v[i]; for (int j = i+1; j < N; j++) { if (v[j] % v[i] == 0) { co -= ans[j].second; } } ans[i] = P(v[i], co); } return ans; } int main() { ll h, w, k; cin >> h >> w >> k; Mint ans = 0; vector

v1 = calc(h), v2 = calc(w); int N = (int)v1.size(), M = (int)v2.size(); /* printf("a\n"); for (auto d: v1) { printf("(%d %d)\n", d.first, d.second); } printf("b\n"); for (auto d: v2) { printf("(%d %d)\n", d.first, d.second); }*/ for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { ans += pow(Mint(k), h*w/lcm(h/v1[i].first, w/v2[j].first))*v1[i].second*v2[j].second; } } ans *= Mint::inv(h)*Mint::inv(w); cout << ans.value() << endl; return 0; }