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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

ULL M = 1000000007;

ULL GCD(ULL a, ULL b) { return (b == 0) ? a : GCD(b, a % b); }

ULL powi(ULL b, ULL i) {
	if (i == 1) return b;
	ULL buf1 = powi(b, i / 2);
	buf1 = buf1 * buf1 % M;
	ULL buf2 = (i % 2) ? b : 1;
	return buf1 * buf2 % M;
}

void solve() {

	ULL h, w, t; cin >> h >> w >> t;
	ULL ty = GCD(h, t), th = h / ty;
	ULL tx = GCD(w, t), tw = w / tx;
	ULL tt = tx * ty;

	ULL per_e = 0;
	per_e += powi(2, th); per_e %= M;
	per_e += powi(2, tw) - 1; per_e %= M;
	ULL g = GCD(th, tw);
	per_e += powi(2, g) + (M - 2); per_e %= M;

	ULL ans = powi(per_e, tt);

	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}
