let flip f x y = f y x

let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d %d %d" @@ fun a b k ->
  let g = gcd a b in
  Printf.printf "%d\n" @@
  flip List.nth (k - 1) @@
  List.filter (fun d -> g mod d = 0) @@
  List.rev @@ Array.to_list @@ Array.init g succ

