#include
using namespace std;
int gcd(int a, int b);//声明最大公约数函数
int main()
{
int num1 = 1;
int num2 = 1;
int lcm = 1;
cin >> num1 >> num2;
while(num1 == 0 || num2 == 0)//判断是否有0值输入,若有则重新输入
{
cout << "input error !" << endl;
cin >> num1 >> num2;
}
lcm = num1 / gcd(num1, num2) * num2;//先除后乘可以在一定程度上防止大数
cout << "The lcm of " << num1 << " and " << num2 << " is: " << lcm << endl;
return 0;
}
int gcd(int a, int b)//函数定义
{
int max = a > b ? a : b;
int min = a < b ? a : b;
a = max;
b = min;
int r = a % b;
if(0 == r)//若a能被b整除,则b就是最大公约数。
return b;
else
return gcd(b, r);//递归
}