One day, Little-Brick(小磚頭) found 3 functions,
GCD, LCM and POWER
GCD(a, b) is to compute the greatest common divisor of a and b,
LCM(a, b) is to compute the least common multiplier of a and b,
POWER(a, b) is to compute ab.
Little-Brick's is not so good as math,
even that he doesn't know how to use these functions,
he doesn't care about it,
he decide to take 4 numbers and substitute them into these functions.
Now, he is asking you to tell him the answer of the result of substitute these 4 numbers into functions in all order,
that is, given you 4 integer A, B, C, D,
you should output the result of GCD(LCM(POWER(A, B), C), D), GCD(POWER(LCM(A, B), C), D), LCM(GCD(POWER(A, B), C), D), LCM(POWER(GCD(A, B), C), D), POWER(GCD(LCM(A, B), C), D), POWER(LCM(GCD(A, B), C), D), each in a single line.
Hint: LCM(a, b) = a * b / GCD(a, b)
You can follow the format of the following suggested code,
or feel free to have your own version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <stdio.h> int gcd(int a, int b) { // your code here } int lcm(int a, int b) { // your code here } int power(int a, int b) { // your code here } int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n", gcd(lcm(power(a, b), c), d)); // ... other 5 lines return 0; } |
ouo.
Note:
Please solve the problem using recursion rather than loop. Practice recursion :)
Input contain 4 integer A, B, C, D, seperate by spaces.
1<= A, B, C, D <= 100
Output contains 6 lines.
Output he result of GCD(LCM(POWER(A, B), C), D), GCD(POWER(LCM(A, B), C), D), LCM(GCD(POWER(A, B), C), D), LCM(POWER(GCD(A, B), C), D), POWER(GCD(LCM(A, B), C), D), POWER(LCM(GCD(A, B), C), D), each in a single line.
It is guarantee that the result of every call of function will < 231