//求最小公倍数!对输入的数据一对一对的进行求解,再与输入的第三个数据进行求解即可!
#include "iostream"
#include "algorithm"
using namespace std;
int main()
{
int testcase, num, i, j, temp1, temp2, temp3;
cin >> testcase;
while (testcase--)
{
cin >> num;
cin >> temp1;
for (i = 1; i < num; i++)
{
temp3 = temp1;
cin >> temp2;
j = min(temp2, temp3);//选取两个数中的最小那个数,进行辗转相除!
while (temp2 % j != 0 || temp3 % j != 0)
{
j = j - 1;
}
temp1 = j * (temp2 / j ) * (temp3 / j);
}
cout << temp1 << endl;
}
}
zoj 1797 Least Common Multiple
最新推荐文章于 2018-03-22 08:43:52 发布