Navigation

Operators and Keywords

Function List:

C++ API

: g = gcd (a1, a2, …)
: [g, v1, …] = gcd (a1, a2, …)

Compute the greatest common divisor of a1, a2, ….

If more than one argument is given then all arguments must be the same size or scalar. In this case the greatest common divisor is calculated for each element individually. All elements must be ordinary or Gaussian (complex) integers. Note that for Gaussian integers, the gcd is only unique up to a phase factor (multiplication by 1, -1, i, or -i), so an arbitrary greatest common divisor among the four possible is returned.

Optional return arguments v1, …, contain integer vectors such that,

g = v1 .* a1 + v2 .* a2 + …

Example code:

gcd ([15, 9], [20, 18])
  ⇒  5  9

See also: lcm, factor, isprime.

Package: octave