关于这道题可以用O(n^2 logn)的时间复杂度过
一点也不惊险的提交记录
(代码仅供测试数据大小,判断质数的部分请勿模仿)
#include<bits/stdc++.h>
using namespace std;
int n;
bool is_prime(int x){
if(x<=1)return 0;
for(int i=2;i<x*log2(x);i++){
if(i==x)continue;
if(x%i==0)return 0;
}
return 1;
}
int main(){
cin>>n;
while(n--){
int x;
cin>>x;
if(is_prime(x))cout<<x<<" ";
}
return 0;
}