#include <stdio.h>
#include <math.h>
#define MAX 1000001
int main()
{
int i=0, j=0, m=0;
bool prime[MAX]={0};
for(i=2; i<MAX; ++i) prime[i] = (i & 1);
m = sqrt(MAX);
for(i=3; i<=m; i+=2)
{
if (prime[i])
{
for(j=i*i; j<MAX; j+=i) prime[j] = false;
}
}
scanf("%d", &m);
for(i=2; i<m; ++i)
{
if (prime[i]) printf("%d ",i);
}
return 0;
}
No comments:
Post a Comment