#include<iostream>
#include<cstdio>
using namespace std;
const int MOD=1000000007;
int n,m,t;
int h,g;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	h=n/gcd(n,t),g=m/gcd(m,t);
	long long res=1;
	res=(res+ksm(2,h)-1)%MOD;
	res=(res+ksm(2,g)-1)%MOD;
	res=(res+ksm(2,gcd(h,g))-2)%MOD;
	res=ksm(res,1LL*(n/h)*(m/g))%MOD;
	printf("%lld",res);
	return 0;
}