let euler28 n =
  let s = ref 1 in
  let k = ref 1 in
  for layer = 1 to (n - 1) / 2 do
    let step = 2 * layer in
    for _ = 1 to 4 do
      k := !k + step;
      s := !s + !k
    done
  done;
  !s

;;

euler28 7
