GCD.Rd
Calculates the greatest common divisor (GCD) and least common multiple (LCM) of all the values present in its arguments.
GCD(..., na.rm = FALSE)
LCM(..., na.rm = FALSE)
The computation is based on the Euclidean algorithm without using the extended
version.The greatest common divisor for
all numbers in the integer vector x
will be computed (the multiple GCD).
A numeric (integer) value.
The following relation is always true:
n * m = GCD(n, m) * LCM(n, m)
Eddelbuettel, D. (2013). Seamless R and C++ Integration with Rcpp. New York, NY: Springer.
GCD(12, 10)
#> [1] 2
GCD(144, 233) # Fibonacci numbers are relatively prime to each other
#> [1] 1
LCM(12, 10)
#> [1] 60
LCM(144, 233) # = 144 * 233
#> [1] 33552
# all elements will be flattened by unlist
GCD(2, 3, c(5, 7) * 11)
#> [1] 1
GCD(c(2*3, 3*5, 5*7))
#> [1] 1
LCM(c(2, 3, 5, 7) * 11)
#> [1] 2310
LCM(2*3, 3*5, 5*7)
#> [1] 210