lcm
lcm Function
Syntax:
lcm &rest integers → least-common-multiple
Arguments and Values:
integer—an integer .
least-common-multiple—a non-negative integer .
Description:
lcm returns the least common multiple of the integers.
If no integer is supplied, the integer 1 is returned.
If only one integer is supplied, the absolute value of that integer is returned.
For two arguments that are not both zero,
(lcm a b) ≡ (/ (abs (* a b)) (gcd a b))
If one or both arguments are zero,
(lcm a 0) ≡ (lcm 0 a) ≡ 0
For three or more arguments,
(lcm a b c ... z) ≡ (lcm (lcm a b) c ... z)
Examples:
(lcm 10) → 10
(lcm 25 30) → 150
(lcm -24 18 10) → 360
(lcm 14 35) → 70
(lcm 0 5) → 0
(lcm 1 2 3 4 5 6) → 60
Exceptional Situations:
Should signal type-error if any argument is not an integer .
See Also:
gcdExpanded Reference: lcm
Basic least common multiple
lcm returns the least common multiple of its integer arguments. With no arguments it returns 1 (the identity element).
(lcm)
=> 1
(lcm 10)
=> 10
(lcm 4 6)
=> 12
(lcm 25 30)
=> 150
Multiple arguments
lcm accepts any number of integer arguments.
(lcm 1 2 3 4 5 6)
=> 60
(lcm -24 18 10)
=> 360
(lcm 14 35)
=> 70
With zero
If any argument is zero, the result is zero.
(lcm 0 5)
=> 0
(lcm 10 0)
=> 0
(lcm 0 0)
=> 0
Negative arguments
lcm always returns a non-negative integer, regardless of the signs of the arguments.
(lcm -4 6)
=> 12
(lcm -3 -5)
=> 15
(lcm -7)
=> 7
Relationship with gcd
For two non-zero integers, lcm and gcd are related by the identity: lcm(a,b) * gcd(a,b) = |a * b|.
(let ((a 12) (b 8))
(= (* (lcm a b) (gcd a b))
(abs (* a b))))
=> T