【模板】埃氏筛法

update:2019.3.13

代码如下

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e7+10;

int n,m;
bool vis[maxn];

void read_and_parse(){
	scanf("%d%d",&n,&m);
	vis[1]=1;
	for(int i=2;i<=n;i++)if(!vis[i]){
		for(int j=i;j<=n/i;j++)vis[i*j]=1;
	}
}

void solve(){
	int q;
	while(m--){
		scanf("%d",&q);
		puts(vis[q]?"No":"Yes");
	}
}

int main(){
	read_and_parse();
	solve();
	return 0;
}
posted @ 2018-12-06 23:17  shellpicker  阅读(489)  评论(0编辑  收藏  举报