Euclid's algorithm for polynomials