import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 U = int(10 ** 4.5 + 10) is_prime = np.zeros(U, np.bool_) is_prime[2] = 1 is_prime[3::2] = 1 for p in range(3, U, 2): if p * p >= U: break if is_prime[p]: is_prime[p * p:: p + p] = 0 primes = np.where(is_prime)[0] def factor(N): div_p = primes[N % primes == 0].tolist() for p in div_p: e = 0 while N % p == 0: N //= p e += 1 yield (p, e) if N > 1: yield (N, 1) def divisor_and_phi(N): div = np.array([1], np.int64) phi = np.array([1], np.int64) for p, e in factor(N): div = np.concatenate([div * pow(p, k) for k in range(0, e + 1)]) phi = np.concatenate([phi] + [phi * (p - 1) * pow(p, k - 1) for k in range(1, e + 1)]) return div, phi H, W, K = map(int, read().split()) period_H, cnt_H = divisor_and_phi(H) period_W, cnt_W = divisor_and_phi(W) period = np.lcm.outer(period_H, period_W).ravel() cnt = np.multiply.outer(cnt_H, cnt_W).ravel() % MOD n_orbit = H * W // period power = np.ones(len(n_orbit), np.int64) KK = K for i in range(64): power *= KK ** ((n_orbit >> i) & 1) power %= MOD KK *= KK KK %= MOD x = (power * cnt % MOD).sum() % MOD x *= pow(H * W, MOD - 2, MOD) x %= MOD print(x)