#include <bits/stdc++.h>
using namespace std;
const int N = 1e8 + 5;
int n, T;
int x;
int vis[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--) {
// f = 0;
memset(vis, 0, sizeof(vis));
cin >> n;
int f = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
int temp = x;
if (f) {
continue;
}
for (int i = 2; i * i <= x; i++) {
if (temp < i) break;
if (!(temp % i)) {
if (vis[i]) {
f = 1;
break;
}
while (temp % i == 0)
temp /= i;
vis[i]++;
}
}
if (temp > 1) {
if (vis[temp])
f = 1;
vis[temp]++;
}
}
if (x == 1 && n == 1) {
cout << "Yes\n";
}
if (n == 2)
cout << "Yes\n";
else if (f)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
当中把 for (int i = 2; i * i <= x; i++)
换成 for (int i = 2 ; i <= sqrt(x); i++)
为啥超时?
求大佬解释!