唯一分解定理
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e9+9;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);//辗转相除法
}
ll lcm(ll a,ll b)//a*b=gcd(a,b)*lcm(a,b)
{
return (a/gcd(a,b)*b);//防止超出范围
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;cin>>T;
while(T--)
{
ll a,b;cin>>a>>b;
cout<<gcd(a,b)<<' '<<lcm(a,b);
cout<<'\n';
}
return 0;
}
tips:c++提供求gcd(最大公因数)的库函数:__gcd(a,b)