let modulo = 1000000007 let moduloL = int64 modulo let ( ++ ) a b = if a + b >= modulo then a + b - modulo else a + b let ( -- ) a b = a ++ (modulo - b) let ( ** ) a b = (int64 a) * (int64 b) % moduloL |> int let rec gcd x y = if y = 0L then x else gcd y (x % y) let lcm x y = x * y / gcd x y let modpow x y = let rec f x y acc = if y = 0L then acc else let acc = if y % 2L = 0L then acc else acc ** x f (x ** x) (y / 2L) acc f x y 1 let modinv x = modpow x (moduloL - 2L) let divisors n = let mutable i = 1 let mutable ret = [] while i * i <= n do if n % i = 0 then ret <- i :: ret if i * i <> n then ret <- (n / i) :: ret i <- i + 1 ret |> List.toArray |> Array.sort let gcdnum n = let ds = divisors n let s = Array.map (fun d -> n / d) ds let n = Array.length ds for i in n - 1 .. -1 .. 0 do for j in 0 .. i - 1 do if ds.[i] % ds.[j] = 0 then s.[j] <- s.[j] -- s.[i] Array.zip ds s do let [|h; w; k|] = stdin.ReadLine().Split() |> Array.map int let hh = gcdnum h let ww = gcdnum w let mutable ans = 0 for d1, s1 in hh do for d2, s2 in ww do let h = int64 h let w = int64 w let d1 = int64 d1 let d2 = int64 d2 let t = h * w / lcm (h / d1) (w / d2) ans <- ans ++ (modpow k t) ** s1 ** s2 ans <- ans ** modinv (h ** w) printfn "%d" ans