#include<iostream>
#define mod 1000000007
using namespace std;
long long gcd(long long a,long long b)
{
	if (b==0)
		return a;
	return gcd(b,a%b);
}
long long fast_pow(long long a,long long b)
{
	if (b==0)
		return 1;
	if (b&1)
		return fast_pow(a*a%mod,b/2)*a%mod;
	else
		return fast_pow(a*a%mod,b/2);
}
int main()
{
	long long n,m,t,n1,n2,m1,m2;
	cin>>n>>m>>t;
	n1=gcd(n,t);
	m1=gcd(m,t);
	n2=n/n1;
	m2=m/m1;
	cout<<fast_pow(fast_pow(2,n2)+fast_pow(2,m2)+fast_pow(2,gcd(n2,m2))-3,n1*m1%(mod-1))<<endl;
	return 0;
}