let rec divisors acc acc' i n =
  match compare n (i * i) with
  | -1 -> List.rev_append acc acc'
  | 0 -> List.rev_append acc (i :: acc')
  | 1 ->
      ( if 0 < n mod i
        then divisors acc acc'
        else divisors (i :: acc) (n / i :: acc') ) (i + 1) n
let divisors = divisors [] [] 1

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let ms = Array.make n 0 in
  let acc = Array.make (n + 1) 0 in
  let acc' = Array.make (n + 1) 0 in
  Printf.printf "%d\n" @@
  List.fold_left max min_int @@
  List.filter (fun d ->
    for i = 0 to n - 1 do
      ms.(i) <- as_.(i) mod d;
    done;
    Array.sort compare ms;
    for i = 0 to n - 1 do
      acc.(i + 1) <- acc.(i) + ms.(i)
    done;
    for i = n - 1 downto 0 do
      acc'.(i) <- acc'.(i + 1) + d - ms.(i)
    done;
    Array.fold_left ( || ) false @@
    Array.init (n + 1) @@ fun i ->
      acc.(i) = acc'.(i) && acc.(i) <= k) @@
  divisors @@
  Array.fold_left ( + ) 0 as_