The Grinnell Scheme Web: The lcm procedure

What does the lcm procedure do?

It computes and returns the least of the positive integers that are evenly divisible by all of its operands. (But if any of its operands is 0, the lcm procedure returns 0; and if it receives no operands at all, it returns 1.)

> (lcm 165 70)
2310
> (lcm -165 -70)
2310
> (lcm 1000 1001)
1001000
> (lcm 12 18 30)
180
> (lcm 360)
360
> (lcm 0 12)
0
> (lcm 60 84 140 210)
420
> (lcm 0 0 0)
0
> (lcm)
1
Do all the operands have to be integers?

Yes. This preserves the analogy between gcd and lcm.


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/lcm.html


created June 24, 1995
last revised December 29, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)