let count_bits n =
  let result = Array.make (n + 1) 0 in
  for i = 1 to n do
    result.(i) <- result.(i / 2) + (i mod 2)
  done;
  let sum = ref 0 in
  for i = 0 to n do
    sum := !sum + result.(i)
  done;
  !sum

;;

count_bits 100
