Debian Codegraph @

man/gcd.Rd

raw
1 \name{gcd}
2 \alias{GCD}
3 \alias{LCM}
4 \title{Greatest Common Divisor and Least Common Multiple}
5 \description{
6 \code{gcd(a,b)} computes the greatest common divisor of two positive
7 integer numbers by Euclid's algorithm.
8
9 \code{lcm(...)} computes the least common multiple of an arbitrary number
10 of integers, iteratively applying \code{lcm(a,b) = (a * b) / gcd(a,b)}.
11 }
12 \usage{
13 GCD(a, b)
14 LCM(n, ...)
15 }
16 \arguments{
17 \item{a, b}{two integer numbers.}
18 \item{n, \dots}{an integer (vector or number) and possibly more; the
19 \code{...} argument is for convenience, allowing e.g., \code{LCM(2,3,4)}.}
20 }
21 \value{
22 a positive integer.
23 }
24 \author{Martin Maechler}
25 \note{
26 Very simple, but too useful to spend time on, if you need it.
27 }
28 \seealso{
29 \code{\link{primes}}, and \code{\link{factorize}}.
30 }
31 \examples{
32 GCD(12, 18)
33 GCD(15, 105)
34 GCD(84, 64)
35
36 LCM(1,2,3,4,5,6) # 60
37 LCM(2,3,5,7) == print(2*3*5*7) # true, of course
38 LCM(1:8) # 840
39
40 ## the LCMs needed to get integer coefficients / N in Taylor polynomial for log(1+x):
41 vapply(1:24, function(n) LCM(1:n), 1)
42 }
43 \keyword{math}
44 \keyword{arithmetic}