11198 - GCD & LCM   

Description

In this problem, you are required to write 2 finctions, gcd() and lcm(), that can help calculate the Greatest Common Divisor (最大公因數) and Least Common Multiple (最小公倍數). The main function will receive multiple positive integers as input values, and it will print the GCD and LCM of all numbers.

The definition of the 2 functions only calculate the GCD or LCM of 2 numbers. These functions are defined as following:

int gcd( int a, int b ) ;      // This returns the GCD of positive integer a and b
int lcm( int a, int b ) ;      // This returns the LCM of positive integer a and b

Please implement these 2 functions in a C source file, we will take care of the input and output.

 

Hint:

You should have already learned about how to calculate GCD by recursive or sequential ways, then we can calcute LCM of 2 numbers a and b by the result of GCD. Suppose D=gcd(a,b), and let a equals p*D and b equals q*D (p and q are relatively prime), then LCM of a and b should be p*q*D, or any other equivalent formats you prefer.

Input

The input contains several (at least 2) positive integers in a line. There are at most 10 integers in the input, and the result of Least Common Multiple can be stored by a 32-bit signed integer.

Output

Print 2 lines as the sample. The first line contains texts like "The Greatest Common Divisor is *." while the second line seems like "The Least Common Multiple is *."

In this homework, you are not required to take care the I/O, yet we hope you can stiil be inspired by the provide the main function.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11198.c

Partial Judge Header

11198.h

Tags




Discuss