题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/*正整数A和正整数B 的最小公倍数是指 能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数。
数据范围: 1≤a,b≤100000
输入描述:输入两个正整数A和B。
输出描述:输出A和B的最小公倍数。*/
int fun5(int x, int y)
{
while (x%y)
{
int temp = x;
x = y;
y = temp%y;
}
return y;
}
int main()
{
int x;
int y;
cin >> x;
cin >> y;
cout << x*y/fun5(x, y) << endl;
system("pause");
return 0;
}
查看23道真题和解析