#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
	if(!b) return a;
	return gcd(b, a % b);
}

ll Pow(ll a, ll b)
{
	ll ans = 1;
	for(; b; b >>= 1)
	{
		if(b & 1) ans = ans * a % MOD;
		a = a * a % MOD;
	}
	return ans;
}

ll H, W, T, g, h;

int main()
{
	cin >> H >> W >> T;
	g = H / gcd(H, T), h = W / gcd(W, T);
	ll ans = 1ll + Pow(2, g) - 1ll + Pow(2, h) - 1ll + Pow(2, gcd(g, h)) - 2ll;
	ans = (ans % MOD + MOD) % MOD;
	ans = Pow(ans, (H / g) * (W / h));
	printf("%lld\n", ans);
	return 0;
}