integer(16)::mo = 10**9 + 7
integer(16)h, w, t
integer(16) gh,gw
integer(16) ans
read*,h,w,t
gh = gcd(h, t)
gw = gcd(w, t)
h =h/ gh
w =w/ gw
ans = mod((power(2_16, h) + power(2_16, w) - 1_16 + mo),mo)
ans = mod((ans + power(2_16,gcd(h, w)) - 2_16 + mo),mo) 
print"(i0)",power(ans, gh * gw)
contains
integer(16) function power(x,y)
integer(16) x,k
integer(16) y,l2
power=1
l2=y
k=x
do
  if(mod(l2,2)==1)power=mod(power*k,mo)
  k=mod(k*k,mo)
  l2=l2/2
  if(l2==0)exit
end do
end function
integer(16) recursive function gcd(a, b)result(res)
  integer(16), intent(in)::a, b
  res=merge(b, gcd(b, mod(a, b)),mod(a, b)==0)
end function
end 
