找质数、素数_算法优化(C++)

void prime(unsigned long max){
	if (max<2) return;
	cout<<"2	3	";
	for (unsigned long i=5; i<=max; i+=2){
		unsigned int ii=(unsigned int)sqrt(i);
		for (unsigned long j=3; j<=ii; j+=2){
			if (i%j==0) goto next;
		}
		cout<<i<<'	';
		next:;
	}
}

网上找到的6N+1,6N+5不靠谱,只能用来排除

posted @ 2021-10-27 18:16  Nolca  阅读(137)  评论(0编辑  收藏  举报