let f x = (x * 2 + 5) mod 17

let floyd_cycle x0 =
  let slow = ref x0 in
  let fast = ref x0 in
  let meet = ref false in
  while not !meet do
    slow := f !slow;
    fast := f (f !fast);
    if !slow = !fast then meet := true
  done;
  slow := x0;
  let mu = ref 0 in
  while !slow <> !fast do
    slow := f !slow;
    fast := f !fast;
    mu := !mu + 1
  done;
  let lam = ref 1 in
  fast := f !slow;
  while !slow <> !fast do
    fast := f !fast;
    lam := !lam + 1
  done;
  !mu * 100 + !lam

;;

floyd_cycle 1
