Problem:
Take 2 numbers as input and print their LCM
Input Format:
number 1
number 2
number 2
Output Format:
LCM
LCM
Constraints:
none
none
Sample Input
15
20
20
Sample Output:
LCM is 60
LCM is 60
Explanations:
60 is LCM of 15 and 20
60 is LCM of 15 and 20
Solution:
chomp($y=<STDIN>);
($a,$b) =($x,$y);
while($b)
{
($a, $b) = ($b, $a % $b)
}
$gcd=$a;
$lcm=($x*$y)/$gcd;
print "LCM is $lcm";
Tips:
LCM= product of numbers/GCD
No comments:
Post a Comment