gcd: Find the Greatest Common Divisor, Smallest Common Multiple, or Coprimality
Description
These functions provide vectorized computations for the greatest common
divisor (gcd), smallest common multiple (scm), and coprimality. Coprime
numbers are also called mutually prime or relatively prime numbers.
The smallest common multiple is often called the least common multiple.
Usage
gcd(m, n)
scm(m, n)
coprime(m, n)
Value
A vector of the length of longest input vector. If one
vector is shorter, it will be recycled. The gcd and scm functions
return an integer vector while coprime returns a logical vector.
Arguments
m, n
integer vectors.
Author
Paul Egeler, MS
Details
The greatest common divisor uses Euclid's algorithm, a fast and widely
used method. The smallest common multiple and coprimality are computed using
the gcd, where \(scm = \frac{a}{gcd(a, b)} \times b\)
and two numbers are coprime when \(gcd = 1\).