int gcd(int a,int b){ //辗转相除法
if(a%b==0) return b;
else return gcd(b,a%b);
}
int lcm(int a,int b){
return a*b/gcd(a,b); //最小公倍数乘最大公约数等于它们的乘积
}
虽然比较简单,但难免有时候想不起来,c++自带了一个函数可以直接拿来用。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while ( cin >> n >> m ) {
cout << __gcd(n,m) << " " << n*m/__gcd(n,m) << endl;
}
// 2 4 --- 2 4
// 15 5 --- 5 15
// 38 4 --- 2 76
return 0;
}