WA求助帖
查看原帖
WA求助帖
911013
songge888楼主2024/7/31 22:22

代码如下

#include<bits/stdc++.h>
using namespace std;
int t,sum[32000],prime[32222],vis[32222];
map<int,int>mp;
void ola(){
    for(int i=2;i<=32220;i++){
        if(!vis[i]){
            prime[++prime[0]]=i;
        }
        for(int j=1;j<=prime[0]&&i*prime[j]<=32220;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0){
                break;
            }
        }
    }
}
bool fundamental_theorem_of_arithmetic (long long x){	
	for(int j=1;j<=prime[0]&&x>=prime[j];j++){
		if(x%prime[j]==0){
			if(mp[prime[j]]){
				return 1;
			}
			mp[prime[j]]=1;
			while(x%prime[j]==0){
				x/=prime[j];
			}
		}
	}
	if(x>1){
		if(mp[x]){
			return 1;
		}
		mp[x]=1;
	}
	return 0;
}
int main(){
	cin>>t;
	ola();
	while(t--){
		int n,a[100005];
		cin>>n;
		mp.clear();
		int flag=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			if(fundamental_theorem_of_arithmetic(a[i])){
				flag=1;
			}
		}
		if(!flag){
			cout<<"No"<<endl;	
		}
		else{
			cout<<"Yes"<<endl;
		}
	}
	
	return 0;
}
2024/7/31 22:22
加载中...