open Printf open Scanf
open Array

let () =
  Scanf.scanf " %d %d %d" @@ fun a b k ->
    let a,b = min a b,max a b in
    init a (fun i -> a-i)
    |> fold_left (fun c v ->
      if a mod v = 0 && b mod v = 0 then
        let c = c+1 in
        if c=k then (
          print_int v; exit 0
        ) else c
      else c
    ) 0
    |> ignore