线性素数筛

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
bool a[10000001];
int n,m;
int tmp;
int main()
{
scanf("%d%d",&n,&m);
a[1]=1;
for(int i=2;i<=n;++i)
{
if(a[i])continue;
for(int j=2;j*i<=n;++j)
a[j*i]=1;
}
for(int i=1;i<=m;++i)
{
scanf("%d",&tmp);
if(!a[tmp])printf("Yes\n");
else printf("No\n");
}
return 0;
}
显示 Gitment 评论