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;
}
全部评论

相关推荐

牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务