Find the greatest common divisor and the least common multiple of pairs of numbers, with Euclid's algorithm.
Input
The first line has t (1 ≤ t ≤ 50). Each of the next t lines has two integers a and b (1 ≤ a, b ≤ 10¹²).
Output
For each pair: the gcd and the lcm, separated by a space.
Examples
Example 1 · Input
3 12 18 252 105 7 13
Expected output
6 36 21 1260 1 91
Example 2 · Input
2 5 5 1 99
Expected output
5 5 1 99
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Euclid: while b != 0: a, b = b, a % b. Then a is the gcd.
Hint 2
lcm(a, b) = a * b // gcd(a, b).
Hint 3
Python's integers never overflow, so 10**12 × 10**12 is fine.
Solution
Show one correct solution (try it yourself first)
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
g = gcd(a, b)
print(g, a * b // g)