You didn’t link the problem, so I’m assuming that it’s not an overflow issue because I can’t see the constraints.
a*b should be in parenthesis. Also, I like to use the inbuilt __gcd(a, b) function rather than making my own.
My code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
long long a, b;
cin >> a >> b;
cout << __gcd(a, b) << " " << (a*b)/__gcd(a, b) << '\n';
}
}