import sys from collections import defaultdict from math import gcd sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) def divisor(n): # nの約数全列挙 res = [] for i in range(1,int(n**.5)+1): if n % i == 0: res.append(i) if i != n//i: res.append(n//i) return res def phi(n): if n == 1: return 1 res = n for i in range(2,int(n**.5)+1): if n % i == 0: res -= res//i while n % i == 0: n //= i if n == 1: # 時間短縮 break else: res -= res//n return res H,W,K = MI() mod = 10**9+7 div_H = divisor(H) div_W = divisor(W) phis = defaultdict() for h in div_H: phis[h] = phi(h) for w in div_W: phis[w] = phi(w) ans = 0 for h in div_H: hh = H//h a = phi(hh) for w in div_W: ww = W//w b = phi(ww) ans += a*b*pow(K,h*w*gcd(hh,ww),mod) ans %= mod ans *= pow(H*W,mod-2,mod) ans %= mod print(ans)