open Printf (* Afficher une liste d'entiers *) let rec pints l = match l with | [] -> print_newline () | [x] -> printf "%d\n" x | x::xs -> printf "%d " x ; pints xs let rec decompose_aux u q x = let v = u / q in if v < q then [ u ] else if u mod q = 0 then q::decompose_aux v q x else decompose_aux u (q + x) (if q < 5 then 2 else x mod 4 + 2) ;; let decompose u = if u < 1 then failwith "decompose" else if u = 1 then [] else decompose_aux u 2 1 ;; let rec communs xs ys = match xs,ys with | [],_ -> [] | _,[] -> [] | x::rx, y::ry -> if x < y then communs rx ys else if y < x then communs xs ry else (* x=y *) x::communs rx ry let rec produit xs = match xs with | [] -> 1 | x::xs -> x*produit xs let pgcd u v = let us = decompose u and vs = decompose v in produit (communs us vs) let u = int_of_string Sys.argv.(1) and v = int_of_string Sys.argv.(2) let r = pgcd u v let _ = printf "%d\n" r ; exit 0