#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, inf = 1e9, maxm = 4e4 + 5;
const int N = sqrt(1e9) + 1;
const int mod = 1e9 + 7;
// const int mod = 998244353;
//const __int128 mod = 212370440130137957LL;
// int a[505][5005];
// bool vis[505][505];
int a[maxn], b[maxn];
bool vis[maxn];
string s;
int n, m;
struct Node{
int val, id;
bool operator<(const Node &u)const{
return val < u.val;
}
};
// Node c[maxn];
int ans[maxn];
int pre[maxn];
vector<int> prime;
//long long ? maxn ?
void solve(){
int res = 0;
int q, k;
cin >> n;
// int mx = 0, mn = inf;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
set<int> S;
for(int i = 1; i <= n; i++){//先把sqrt(1e9)的素数筛出来,再进行质因数分解,不然会超时
for(auto x : prime){
if(a[i] % x == 0){
if(S.count(x)){
cout << "Yes\n";
return;
}
S.insert(x);
while(a[i] % x == 0){
a[i] /= x;
}
}
}
if(a[i] > 1){
if (S.count(a[i])){
cout << "Yes\n";
return;
}
S.insert(a[i]);
}
}
cout << "No\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//素数筛
for(int i = 2; i <= N; i++){
if(!vis[i]){
prime.pb(i);
}
for(int j = 2 * i; j <= N; j += i){
vis[j] = 1;
}
}
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round 837 (Div. 2) C. Hossam and Trainees
最新推荐文章于 2024-11-18 16:46:21 发布
这篇文章描述了一个C++程序,用于判断给定一组整数,是否存在不超过sqrt(1e9)的素数可以将它们完全质因数分解。如果存在,输出Yes,否则输出No。
摘要由CSDN通过智能技术生成