这个也需要优化,使枚举的次数更少
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int x;
cin>>x;
bool s=true;
for(int i=2;i*i<=x;i++)
if(x%i==0)
{
s=false;
break;
}
if(s) cout<<x<<" is prime"<<endl;
else cout<<x<<" is not prime"<<endl;
}
return 0;
}