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

13 lines
174 B
Perl
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
sub gcd {
my ($x, $y) = @_;
while ($x) { ($x, $y) = ($y % $x, $x) }
$y
}
sub lcm {
my ($x, $y) = @_;
($x && $y) and $x / gcd($x, $y) * $y or 0
}
print lcm(1001, 221);