题解 | #求最小公倍数#
求最小公倍数
http://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
#include <bits/stdc++.h>
using namespace std;
//辗转相除法求公约数
int yueshu(int a, int b){
if(a < b) swap(a, b);
int num = b;
while(a%b != 0){
num = a % b;
a = b;
b = num;
}
return b;
}
int main(){
int a, b;
while(cin >> a >> b){
//两数乘积除以最小公约数,可得最大公倍数
int num = yueshu(a, b);
cout << (a/num)*b << endl;
}
return 0;
}