(* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? *) let lcm l = (* remove multiples of x in l *) let rem_mult x l = List.map ( fun y -> if (y mod x=0) then (y/x) else y) l in (* iterative reduce multiples of list members *) let rec red_mult l = match l with [] -> [] | h::t -> h::(red_mult (rem_mult h t)) in List.fold_left ( * ) 1 ( red_mult l ) ;; (* proper divisors below n: list of numbers below n, but greater than 1 *) let pdb n = let rec pdb n l = if (n<2) then l else pdb (n-1) (n::l) in pdb n [] ;; Printf.printf "%d\n" (lcm (pdb 20));