#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