rt,感觉思路没有问题,还是说我的做法并不是正解
#include<bits/stdc++.h>
typedef long long LL;
const int N=5e5+5;
LL T;
LL arr[N];
inline LL gcd(LL x,LL y){
if(!y) return x;
return gcd(y,x%y);
}
inline LL lcm(LL x,LL y){
return (x*y)/gcd(x,y);
}
inline LL find_gcd(std::vector<LL>vt){
LL gcder=vt[0];
for(LL i=1;i<vt.size();i++){
gcder=gcd(gcder,vt[i]);
if(gcder==1) return 1;
}
return gcder;
}
inline LL find_lcm(std::vector<LL>vt){
LL lcmer=vt[0];
for(LL i=1;i<vt.size();i++){
lcmer=lcm(lcmer,vt[i]);
}
return lcmer;
}
std::vector<LL>vt;
LL a_t=1,g,l;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>T;
while(T--){
LL n;
std::cin>>n;
while(n--){
LL x;
std::cin>>x;
vt.push_back(x);
}
while(n--){
for(LL i=0;i<vt.size();i++) a_t*=vt[i];
g=find_gcd(vt),l=find_lcm(vt);
if(a_t!=g*l){
puts("No");
vt.clear();
a_t=1;
break;
}
else{
puts("Yes");
vt.clear();
a_t=1;
break;
}
}
}
return 0;
}