递归实现,辗转相除法。
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
if(a % b == 0)
return b;
else{
int temp = b;
b = a % b;
a = temp;
gcd(a, b);
}
}
int lcm(int a, int b)
{
/**< 求最小公倍数 */
int n = a, m = b;
int re = gcd(n, m);
return a * b / re;
}
int main(){
int a, b;
while(cin >> a >> b){
cout << lcm(a,b) << endl;
}
return 0;
}