# [LON-CAPA-users] least common multiple

Gerd Kortemeyer lon-capa-users@mail.lon-capa.org
Wed, 1 Jun 2005 18:13:47 -0400

```Hi Sally,

But I assume you want to do this in LON-CAPA.

We have no built-in function or this, but the least common multiple
is the product of the two numbers divided by the greatest common
denominator. Use Euclid for the latter:

sub gcd {
my (\$a,\$b)=@_;
while (\$a!=\$b) {
if (\$a>\$b) {
\$a-=\$b;
} else {
\$b-=\$a;
}
}
return \$a;
}

sub lcm {
my (\$a,\$b)=@_;
return \$a*\$b/&gcd(\$a,\$b);
}

- few people know that Euclid originally implemented this in Perl on
the bonus CD that came with the 300BC edition of his Elements.

If you want to use these functions more often, put them into a library.

- Gerd.

On Jun 1, 2005, at 5:07 PM, Lars Jensen wrote:

> Hi Sally,
>
> Yacas' Lcm command will do this (and much more). Yacas is a
> Computer algebra system available from:
>
> http://yacas.sourceforge.net/
>
> The windows version is here:
>
> http://www.xs4all.nl/~apinkus/backups/YacasWindowsBinary-1.0.54.zip
>
> Enter for exampleL
>
> In> Lcm(12,18);
>
> and you get:
>
> Out> 36;
>
> Lars.
> Sally Hunnicutt wrote:
>
>> Hello,
>> Is there a PERL script function that determines the least common
>> multiple of two integers?
>> Thanks,
>> Sally
>> Dr. Sally S. Hunnicutt
>> Assistant Chair, Associate Professor
>> VCU Department of Chemistry
>> 1001 W. Main St.
>> PO Box 842006
>> Richmond VA 23284-2006
>> 804-827-0531
>> sshunnic@vcu.edu
>> _______________________________________________
>> LON-CAPA-users mailing list
>> LON-CAPA-users@mail.lon-capa.org
>> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>>
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>

```