1246.prime SDNUOJ 1246
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 <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
int n;
while(~scanf("%d", &n))
{
for(int i = 0; i < n; ++i)
{
int a;
scanf("%d", &a);
if(a == 1)
{
cout << 'Y' << '\n';
continue;
}
int j;
for(j = 2; j <= sqrt(a); ++j)
{
if(a % j == 0)
break;
}
if(j > sqrt(a))
cout << 'N' << '\n';
else
cout << 'Y' << '\n';
}
}
return 0;
}