let factor n =
  let result = ref [] in
  let m = ref n in
  let d = ref 2 in
  while !m > 1 do
    if !m mod !d = 0 then begin
      result := !d :: !result;
      m := !m / !d
    end else
      d := !d + 1
  done;
  List.rev !result

;;

List.fold_left (+) 0 (factor 360)
