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

13 lines
174 B
Perl
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
sub gcd {
2018-06-22 20:57:24 +00:00
my ($x, $y) = @_;
while ($x) { ($x, $y) = ($y % $x, $x) }
$y
2013-04-10 21:29:02 -07:00
}
sub lcm {
2018-06-22 20:57:24 +00:00
my ($x, $y) = @_;
($x && $y) and $x / gcd($x, $y) * $y or 0
2013-04-10 21:29:02 -07:00
}
print lcm(1001, 221);