sdnu1246(素数 暴力)
1246.prime
Description
This is a verrrrrrrrrry easy problem, when Lulichuan was a freshman, he can ease to judge whether a number is a prime, there some TestCase, you just need to judge if the number is a prime, if it’s a prime output “N”, else output “Y”
Input
The first line is T(0 < T < 100000)Then follow T line, every line is a number n(0 < n <100000000)
Output
As stated in the title
Sample Input
5
1
2
3
4
5
Sample Output
Y
N
N
Y
N
#include<bits/stdc++.h>
using namespace std;
//const int N=1e8;
//int vis[N];
int main()
{
int n,m,t,i,j;
// memset(vis,0,sizeof(vis));
// vis[0]=1;///素数为0
// vis[1]=1;
// for(i=2; i<N; i++)
// {
// for(j=2*i; j<N; j+=i)
// vis[j]=1;
// }
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n==1)
cout<<"Y"<<'\n';
else
{
bool f=1;
for(i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
f=0;
break;
}
}
if(f)
cout<<"N"<<'\n';
else
cout<<"Y"<<'\n';
}
}
return 0;
}