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

14 lines
208 B
Perl
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
sub lcm {
use integer;
my ($x, $y) = @_;
2018-06-22 20:57:24 +00:00
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;
2013-04-10 21:29:02 -07:00
}
2018-06-22 20:57:24 +00:00
$f
2013-04-10 21:29:02 -07:00
}
print lcm(1001, 221);