# coding: utf-8 # Your code here! """ 素因数分解 input: N output: [[p1,e1],[p2,e2],...] の形で素因数分解する。 N=1なら空のリストを返す """ def prime_factorize(N): #素因数分解 exponent = 0 while N%2 == 0: exponent += 1 N //= 2 if exponent: factorization = [[2,exponent]] else: factorization = [] i=1 while i*i <=N: i += 2 if N%i: continue exponent = 0 while N%i == 0: exponent += 1 N //= i factorization.append([i,exponent]) if N!= 1: factorization.append([N,1]) assert N != 0, "zero" return factorization def factorization_to_divisors(fac): res = [1] for p,e in fac: nres = [] for x in res: for i in range(e+1): nres.append(x) x *= p res = nres return res 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) は gcd(i,h)*gcd(j,w)の自由度を持つ 自由度 a*b なる (i,j) の個数は phi(h/a)*phi(h/b) """ hfac = prime_factorize(h) wfac = prime_factorize(w) hdiv = factorization_to_divisors(hfac) wdiv = factorization_to_divisors(wfac) div = list(set(hdiv+wdiv)) ph = [p for p,e in wfac] pw = [p for p,e in hfac] primes = list(set(ph+pw)) 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) from math import gcd def lcm(x,y): return x//gcd(x,y)*y num = {} for a in hdiv: for b in wdiv: d = lcm(a,b) if d in num: num[d] += totient[a]*totient[b] else: num[d] = totient[a]*totient[b] ans = 0 MOD = 10**9+7 for d,v in num.items(): ans += v*pow(k,a*b//d,MOD)%MOD ans %= MOD print(ans*pow(h*w,MOD-2,MOD)%MOD)