题目
输入 2个正整数A ,B ,求 A 与 B 的最小公倍数。
input
2 个数 A,B ,中间用空格隔开。 (1≤A,B≤109)
Output
输出A 与 B 的最小公倍数。
Sample 1
Input | Output |
30 105 | 210 |
Status
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
long long a,b,c,d,z;
cin>>a>>b;
c=a*b; //c为a,b的乘积
if(b>a){ //b>a时 。交换a,b
z=b;
b=a;
a=z;
}
while(a%b){ //a对b取余不为0
z=b;
b=a%b;
a=z;
}
c=c/b;
// cout<<b<<endl; //最大公约数
cout<<c<<endl; //最小公倍数
}
可以和最大公约数问题一起解决。