#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; } } vector g_prime; const int MAX_PRIME=100000; bool is_prime_[(MAX_PRIME+1)/2] ; bool is_prime(ll_t x){ if(x==2) return true; if(x<=1 || x%2==0) return false; return is_prime_[x/2]; } void setup_prime() { fill_n(is_prime_ , (MAX_PRIME+1)/2 , true); g_prime.clear() ; g_prime.push_back(2); for(int i=3;i<=MAX_PRIME;i+=2){ if(!is_prime_[i>>1]) continue; g_prime.push_back(i); for(int j=i+i+i;j<=MAX_PRIME;j+=i+i){ is_prime_[j>>1]=false; } } } // Euler function map memo; ll_t phi(ll_t x){ ll_t xx = x; if(memo.count(x)) return memo[x]; ll_t val = x; for(int i=0;i<(int)g_prime.size();i++){ if(g_prime[i] > x) break; if(x % g_prime[i] == 0){ val = val / g_prime[i] * (g_prime[i] - 1) ; while(x % g_prime[i] == 0) x /= g_prime[i]; } } if(x>1){ val = val / x * (x - 1) ; } return memo[xx] = val; } 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; } long long solve(long long w,long long h, int k){ auto a = aliquot(h); auto b = aliquot(w); long long ans = 0; for(auto pa : a){ for(auto pb : b){ long long groupNum = w * h / lcm(pa, pb); ans += modpow(k, groupNum, mod) * phi(pa) % mod * phi(pb); ans %= mod; } } ans *= inv(w * h, mod); ans %= mod; return ans; } int main() { setup_prime(); int h, w, k; cin>>h>>w>>k; cout<