let flip f x y = f y x

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