96分,最后一个点TLE,帮我看看呗
#include<bits/stdc++.h>
using namespace std;
long long a[500005];
long long gcd(long long a,long long b){
if(a % b == 0) return b;
else return gcd(b,a%b);
}
void solve(){
int n; scanf("%d",&n);
for(int i = 1; i <= n; i++) scanf("%lld",&a[i]);
if(n == 2){
cout << "Yes\n";
return ;
}
long long gc = a[1];
for(int i = 2; i <= n; i++) gc = gcd(gc,a[i]);
if(gc != 1){
cout << "No\n";
return ;
}
set<long long> s;
for(int i = 1; i <= n; i++){
for(long long j = 2; j * j <= a[i]; j++){
if(a[i] < j) break;
if(a[i] % j == 0){
if(s.count(j) != 0){
cout << "No\n";
return ;
}
s.insert(j);
while(a[i] % j == 0) a[i] /= j;
}
}
if(a[i] != 1){
if(s.count(a[i]) != 0){
printf("No\n");
return ;
}
s.insert(a[i]);
}
//for(auto it = s.begin(); it != s.end(); it++) cout << *it << " ";
}
printf("Yes\n");
return ;
}
int main()
{
int t; cin >> t;
while(t--) solve();
return 0;
}