Source

spoj-ocaml / 00011.FCTRL / fctrl.ml

Full commit
(* https://www.spoj.pl/problems/FCTRL/ *)

open Nativeint

let (+/) = add
let (|>) x y = y x
let id x = x


let rec z_aux accu n x =
  if      n < x then accu
  else if x > 200000000 then accu +/ of_int (n / x)
  else                       z_aux (accu +/ of_int (n / x)) n (x * 5)

let z n = z_aux zero n 5


let main () =
  let t = Scanf.scanf "%d\n" id in
  for i = 1 to t do
    let n = Scanf.scanf "%d\n" id in
    n |> z |> to_string |> print_endline
  done

let () = main ()