1106 质数检测 【简单素数判断】

来源:互联网 发布:淘宝网运营方式 编辑:程序博客网 时间:2024/06/04 18:58

1106质数检测
基准时间限制:1 秒 空间限制:131072 KB 分值:0难度:基础题
收藏
关注
取消关注
给出N个正整数,检测每个数是否为质数。如果是,输出"Yes",否则输出"No"。
Input
第1行:一个数N,表示正整数的数量。(1 <= N <= 1000)第2 - N + 1行:每行1个数(2 <= S[i] <= 10^9)
Output
输出共N行,每行为 Yes 或 No。
Input示例
523456
Output示例
YesYesNoYesNo
#include<iostream>#include<algorithm>#include<string.h>#include<cmath>using namespace std;int main(){int n,x;;cin>>n;while(n--){cin>>x;int flag=0;if(x==2)flag=1;else{for(int i=3;i<=sqrt(x);i+=2)if(x%i==0){flag=1;break;}}if(flag)cout<<"no"<<endl;else cout<<"yes"<<endl;}return 0;}

原创粉丝点击