let solve cl b =
let rec loop = function
| [] -> assert false
| [c0] -> (c0, [b / c0])
| c0 :: c1 :: l ->
let (d,e1,e2) = euclid c0 c1 in
match loop (d :: l) with
| e, x :: xs ->
(e, (e1 * x) :: (e2 * x) :: xs)
| _ -> assert false
in
let (d,xs) = loop cl in
if is_int (b / d) then Some(d,xs) else None