Hello coders, today we are going to solve GCD and LCM CodeChef Solution whose Problem code is FLOW016.
Problem
Two integers A and B are the inputs. Write a program to find GCD and LCM of A and B.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer A and B.
Output
Display the GCD and LCM of A and B separated by space respectively. The answer for each test case must be displayed in a new line.
Constraints
- 1 <= T <= 1000
- 1 <= A, B <= 100000
Example
Input:
3 120 140 10213 312 10 30
Output:
20 840 1 3186456 10 30
Solution - GCD and LCM - CodeChef Solution
Python 3
#Solution Provided by Sloth Coders T = int(input()) for i in range(T): num = [int(x) for x in input().split(' ')] a = min(num) b = max(num) multiply = a*b while(b): a,b = b,a%b hcf = a lcm = multiply/hcf print(hcf,int(lcm))
Disclaimer: The above Problem (GCD and LCM) is generated by CodeChef but the Solution is provided by Sloth Coders.
A Sloth Who loves to Code
Also Read: