import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

const val mod = (1e9 + 7).toInt()

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val H = sc.nextLong()
    val W = sc.nextLong()
    val t = sc.nextLong()

    val w = gcd(W, t)
    val h = gcd(H, t)

    var res = 0L

    val x = H / h
    val y = W / w
    res = (res + pow(2, x)) % mod
    res = (res + pow(2, y)) % mod
    res = (res + pow(2, gcd(x, y))) % mod
    res = (res - 3 + mod) % mod

    res = pow(res, w * h)

    println(res)
    /*val n = sc.nextLong()
    val m = sc.nextLong()
    val T = sc.nextLong()
    val gn = gcd(T, n)
    val gm = gcd(T, m)
    val mod = 1000000007
    val q = gcd(n / gn, m / gm)
    var res = 0L
    res = (res + pow(2, q)) % mod
    res = (res + pow(2, n / gn)) % mod
    res = (res + pow(2, m / gm)) % mod
    res = (res - 3 +mod) % mod
    println(pow(res, gn * gm))*/
}

fun inv(h: Long): Long = pow(h, (mod - 2).toLong())

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
fun pow(a: Long, x: Long): Long {
    var res = 1L
    var x = x
    var a = a
    while (x > 0) {
        if (x % 2 == 1L) res = (res * a) % mod
        a = (a * a) % mod
        x /= 2
    }
    return res
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}