#include<iostream>
#include<cmath>
using namespace std;
int gcd(int a, int b){
while (a%b){
int temp;
temp = a;
a = b;
b = temp%a;
}//求最大公约数
return b;
}
int main(){
int a, b;
cin >> a>>b;
cout << a*b / gcd(a, b);
return 0;
}
本文介绍了一个简单的C++程序,该程序利用辗转相除法计算两个整数的最大公约数,并进一步计算这两个数的最小公倍数。通过输入两个整数,程序能够快速给出结果。
#include<iostream>
#include<cmath>
using namespace std;
int gcd(int a, int b){
while (a%b){
int temp;
temp = a;
a = b;
b = temp%a;
}//求最大公约数
return b;
}
int main(){
int a, b;
cin >> a>>b;
cout << a*b / gcd(a, b);
return 0;
}
1150

被折叠的 条评论
为什么被折叠?