想到了一个朴素办法,但是会TLE 。没想起来根号法。
#include<iostream>
using namespace std;
int main()
{
//freopen("xxx.in","r",stdin);
//freopen("yy.out","w",stdout);
int n;
bool flag;
int c;
cin >> n;
for(int i=0;i<n;i++)
{
flag=true;
cin >> c;
for(int j=2;j*j<=c;j++)
{
if(c%j==0)
{
flag=false;
break;
}
}
if(flag)
{
cout << c << " is prime" << '\n';
}
else
{
cout << c << " is not prime" << '\n';
}
}
//fclose(stdin);
//fclose(stdout);
return 0;
}