RosettaCodeData/Task/Least-common-multiple/Perl/least-common-multiple-2.pl

14 lines
208 B
Perl
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
sub lcm {
use integer;
my ($x, $y) = @_;
my ($f, $s) = @_;
while ($f != $s) {
($f, $s, $x, $y) = ($s, $f, $y, $x) if $f > $s;
$f = $s / $x * $x;
$f += $x if $f < $s;
}
$f
}
print lcm(1001, 221);