Euclidean algorithm for polynomials