关于最大公约数,请见我上一篇博文:https://blog.youkuaiyun.com/qq_36770641/article/details/88724619
附C++代码:(输入两个均为正整数的情况,其他情况请自行考虑。)
#include <iostream>
using namespace std;
int GCD(int a,int b){ // 求最大公约数
int temp=0;
while(b!=0){
temp=a;
a=b;
b=temp%b;
}
return a;
}
int main(int argc, const char * argv[]) {
int a,b;
int gcd;
int lcm;
while (cin>>a>>b) {
gcd=GCD(a, b);
lcm=a*b/gcd;
cout<<lcm<<endl;
}
return 0;
}