Scanf.scanf "%d" (fun n -> let k = 1_000_000_000_000 in let rec loop i acc overflow = if acc mod k = 0 then print_endline "000000000000" else if i > n then (if overflow then Printf.printf "%012d\n" acc else Printf.printf "%d\n" acc ) else let acc = acc * i in if acc >= k then loop (i + 1) (acc mod k) true else loop (i + 1) acc overflow in loop 1 1 false )