integer(16)::mo = 10**9 + 7
integer h, w, t
integer(16) gh,gw,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) recursive function power(x,y)result(res)
    integer(16) x
    integer y
    res=1_16
    if (y==0_16)then
        return
    endif
    res=mod(power(x,y-1_16)*x,mo)
end function
integer recursive function gcd(a, b)result(res)
  integer, intent(in)::a, b
  res=merge(b, gcd(b, mod(a, b)),mod(a, b)==0)
end function
end 