本蒟蒻源代码如下:
#include <iostream>
#include <set>
#include <algorithm>
#include <cstring>
#include <numeric>
#define LL long long
using namespace std;
//#define __algo_gcd __gcd
//vscode上使用__algo_gcd
set<int> a;
int T, n, acopy[500009];
int G(){
// 计算最大公因数
set<int>::iterator it = a.begin();
int pre = *it, cnt = a.size();
++it;
while (cnt >= 2){
pre = __algo_gcd(pre, *it);
++it;
--cnt;
}
return pre;
}
int L(){
// 计算最小公倍数
set<int>::iterator it = a.begin();
int pre = *it, cnt = a.size();
++it;
while (cnt >= 2){
pre = (pre * (*it)) / __algo_gcd(pre, *it);
++it;
--cnt;
}
return pre;
}
bool check(){
// 检查是否符合条件
int g = G();
int l = L();
LL tmp = g*l;
LL tmp2 = 1;
for (int i=1; i<=n; i++){
tmp2 *= acopy[i];
}
if (tmp == tmp2)
return true;
return false;
}
int main(){
scanf("%d", &T);
for (int i=1; i<=T; i++){
// 清空
a.clear();
memset(acopy, 0, sizeof(acopy));
scanf("%d", &n);
for (int j=1; j<=n; j++){
//逐个输入
int tmp;
scanf("%d", &tmp);
a.insert(tmp);
acopy[j] = tmp;
}
if(check())
printf("Yes");
else
printf("No");
// 特殊处理换行符(强迫症
if (i!=T)
printf("\n");
}
// 保险起见qwq
return 0;
}
说明:本蒟蒻仅#13为AC,其他全部为WA,没有TLE或MLE
求助dalao,谢谢!
好人一生平安