求助80分
查看原帖
求助80分
793625
Pink_Cut_Tree楼主2023/7/22 21:28

TLE了一堆

#include<iostream>
#include<algorithm>
using namespace std;
int T,n,num[500005],flag;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--){
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>num[i];
		}
		if(n==2){
			puts("Yes"); continue;
		}
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(__gcd(num[i],num[j])!=1){
					flag=1; break;
				}
			}
			if(flag==1){
				break;
			}
		}
		if(flag==0){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
return 0;	
}  
2023/7/22 21:28
加载中...