def divisor_list(N): #約数のリスト if N == 1: return [1] res = [] for i in range(1,N): if i*i >= N: break if N%i == 0: res.append(i) res.append(N//i) if i*i == N: res.append(i) return sorted(res) def prime_factors(N): #素因数のリスト factors = [] if N&1==0: factors = [2] while N%2 == 0: N //= 2 else: factorization = [] M = int(N**0.5)+1 for i in range(3,M,2): if N%i==0: while N%i == 0: N //= i factors.append(i) if N!= 1: factors.append(N) assert N != 0, "zero" return factors # coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline read = sys.stdin.read h,w,k = [int(i) for i in read().split()] """ Polya (i,j) in Z/(h)*Z/(w) の周期は lcm(h//gcd(i,h),w//gcd(j,w)) なので、 自由度は d := h*w//lcm(h//gcd(i,h),w//gcd(j,w)) = gcd(i,h)*gcd(j,w)*gcd(h//gcd(i,h),w//gcd(j,w)) gcd(i,h) = a なる i は phi(h//a) 個ある """ hdiv = divisor_list(h) wdiv = divisor_list(w) div = list(set(hdiv+wdiv)) primes = list(set(prime_factors(h)+prime_factors(w))) totient = {i:i for i in div} for x in div: for p in primes: if x%p==0: totient[x] = totient[x]//p*(p-1) ans = 0 hw = h*w MOD = 10**9+7 from math import gcd # ここでは、aa = h//a, bb = w//b のつもり for aa in hdiv: for bb in wdiv: d = hw//(aa*bb)*gcd(aa,bb) ans += totient[aa]*totient[bb]%MOD*pow(k,d,MOD)%MOD print(ans*pow(hw,MOD-2,MOD)%MOD)