#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BET(a,b,c) ((a)<=(b)&&(b)<(c)) #define FOR(i,n) for(int i=0,i##_end=(int(n));i VI; typedef vector VVI; typedef long long ll_t; ll_t gcd(ll_t s, ll_t t){ return t ? gcd(t , s % t) : s;} ll_t lcm(ll_t s, ll_t t){ return s/gcd(s,t)*t; } ll_t modpow(ll_t x , ll_t y , ll_t mod){ x %= mod; ll_t t = x, res = 1; for(; y ; y >>= 1){ if(y & 1) { res = res * t; if(res >= mod) res %= mod; } t = t * t; if(t >= mod) t %= mod; } return res; } ll_t exgcd(ll_t a, ll_t b, ll_t &x, ll_t &y) { if(b == 0) { x = 1; y = 0; return a; } else { ll_t d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } } ll_t inv(ll_t a, ll_t mod) { ll_t x, y; if (exgcd(a, mod, x, y) == 1){ return (x + mod) % mod; } else { return -1; } } const int mod = 1000000007; vector aliquot(int x){ VI r ; for(int i=1;i*i<=x;i++){ if(x % i == 0){ r.push_back(i); if(i != x / i) r.push_back(x/i); } } sort(ALL(r)); return r; } map calc(long long x){ map dp; VI a = aliquot(x); for(int i=SZ(a)-1;i>=0;i--){ int val = 0 ; val = x / a[i]; for(int j=i+1;j a, b; a = calc(h); b = calc(w); long long ans = 0; for(auto pa : a){ for(auto pb : b){ long long groupNum = w * h / lcm(h / pa.first, w / pb.first); ans += modpow(k, groupNum, mod) * pa.second % mod * pb.second; ans %= mod; } } ans *= inv(w * h % mod, mod); ans %= mod; return ans; } int main() { int h, w, k; cin>>h>>w>>k; cout<