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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值