#pragma warning(disable:4996);
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<time.h>
#include<stdlib.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
int main() {
int n;
scanf("%d", &n);
while (n--) {
int m;//注意m的个数若为1则直接输出该数即可,大于则利用欧几里得算法求最大公因数,从而得到最小公倍数即可
scanf("%d", &m);
if (m >= 2) {
int x, y;
scanf("%d%d", &x, &y);
long long ans = x / gcd(x, y) * y;
for (int i = 0;i < m - 2;i++) {
int t;
scanf("%d", &t);
ans = ans / gcd(ans, t) * t;
}
cout << ans << endl;
}
else {
int x;
scanf("%d", &x);
cout << x << endl;
}
}
return 0;
}
问题 A: Least Common Multiple
最新推荐文章于 2021-04-06 21:34:19 发布