let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let makeDivList n =
  List.filter (fun x -> n mod x = 0) (Array.to_list (Array.init n (fun i -> i+1)))
let f a b k = List.nth (makeDivList (gcd a b)) (k-1)
let () = Scanf.scanf "%d %d %d\n"
    (fun a b k -> f a b k) |> print_int