#include using namespace std; long long i, j, l, r, mid, p, q, k, t, n, m, a, b, c, d, h, w, ans, cnt, res, arr[1000005]; const long long mod = 1e9 + 7, mod2 = 999993469, inf = 1e18; string s; bool check; long long binpow (long long a, long long b, long long mod){ a %= mod; long long res = 1; while (b > 0){ if (b % 2 == 1){ res = res * a % mod; } a = a * a % mod; b /= 2; } return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> h >> w >> k; ans = 0; for (i = 0; i < h; i += 1){ for (j = 0; j < w; j += 1){ c = h / __gcd(i, h); d = w / __gcd(j, w); res = __gcd(i, h) * __gcd(j, w) % mod * __gcd(c, d) % mod; ans = (ans + binpow(k, res, mod)) % mod; } } cout << ans * binpow(h * w, mod - 2, mod) % mod << "\n"; }