Prime prime screening of screening

This is a prime number screening most simplest way

The core idea is to use factor, a 0-1 mark

#define maxn 1000000

int prime[maxn + 5] = {1, 1, 0};

void init(){
	for(int i = 1; i <= maxn ; i++){
		if(prime[i]) continue;
	for(int j = 2 * i; j <= maxn; j += i){
		prime[j] = 1;
	}
}
Published 48 original articles · won praise 5 · Views 765

Guess you like

Origin blog.csdn.net/weixin_43899266/article/details/103745642