素数(质数)超快 埃拉托斯尼“筛法” 自带序号的数据类型
作者:互联网
#include<iostream>
#include<bitset>
#include<cmath>
using namespace std;
int main()
{
int const max_number(1000000);
int const max_test((int)sqrt((double)max_number));
bitset<max_number+1> numbers;
numbers.set();
numbers[0]= 0;
numbers[1] = 0;
for(int i(1);i!=max_test;++i)
{
if(numbers[i])
{
for(int j(i*i);j<max_number+1;j+=i)
{
numbers[j]=0;
}
}
}
cout<<numbers.count()<<endl;
for(int i(1);i!=1000000;++i)
{
if(numbers[i])
{
cout<<i<<" ";
}
}
return 0;
}
From liebao
标签:const,超快,int,max,质数,数据类型,number,numbers,include 来源: https://blog.csdn.net/qq_41502468/article/details/121233298