Problem:
Take 2 numbers as input and print their GCD
Input Format:
number 1
number 2
number 2
Output Format:
GCD
GCD
Constraints:
none
none
Sample Input
6
9
9
Sample Output:
GCD is 3
GCD is 3
Explanations:
3 is GCD of 6 and 9
3 is GCD of 6 and 9
Solution:
chomp($b=<STDIN>);
while($b)
{
($a, $b) = ($b, $a % $b)
}
print "GCD is $a";
Tips:
Learn the logic of GCD
No comments:
Post a Comment