let digit_sum n =
  let m = ref n in
  let s = ref 0 in
  while !m > 0 do
    s := !s + !m mod 10;
    m := !m / 10
  done;
  !s

let count_harshad limit =
  let c = ref 0 in
  for n = 1 to limit do
    if n mod (digit_sum n) = 0 then c := !c + 1
  done;
  !c

;;

count_harshad 100
