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

全部评论

相关推荐

10-28 11:04
已编辑
美团_后端实习生(实习员工)
一个2人:我说几个点吧,你的实习经历写的让人觉得毫无含金量,你没有挖掘你需求里的 亮点, 让人觉得你不仅打杂还摆烂。然后你的简历太长了🤣你这个实习经历看完,估计没几个人愿意接着看下去, sdk, 索引这种东西单拎出来说太顶真了兄弟,好好优化下简历吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务