# GCD of two polynomials with the Euclidean algorithm: gcd Gcd

### 5.28.5 GCD of two polynomials with the Euclidean algorithm: gcd Gcd

The gcd command computes the gcd (greatest common divisor) of polynomials. (See also 5.5.1 for GCD of integers.)

- gcd takes an unspecified number or arguments:
  polys, a sequence or list of polynomials.
- gcd(polys) returns the greatest common divisor of the polynomials in polys.

#### Examples.

- Input:
  gcd(x^2+2*x+1,x^2-1)
  Output:

  x+1

- Input:
  gcd(x^2-2*x+1,x^3-1,x^2-1,x^2+x-2)
  or:
  gcd([x^2-2*x+1,x^3-1,x^2-1,x^2+x-2])
  Output:

  x−1

- For polynomials with modular coefficients:
  Input (e.g.):
  gcd((x^2+2*x+1) mod 5,(x^2-1) mod 5)
  Output:

  | ⎛ ⎝ | 1%5 | ⎞ ⎠ | x+1%5