Scanf.scanf "%d %d %d" (fun a b k ->
    let rec loop i l =
        if i = 0 then l else
            let l = if a mod i = 0 && b mod i = 0 then i :: l else l in
            loop (i - 1) l
    in
    let l = loop (max a b) [] in
    Printf.printf "%d\n" (Array.of_list (List.rev l)).(k - 1)
)