You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
350 B
22 lines
350 B
#include<cstdio>
|
|
#define MAXN 2000001
|
|
int a[MAXN],i,j;
|
|
int main() {
|
|
int m;
|
|
while(scanf("%d",&m) == 1 && m!=0) {
|
|
for(i = 2; i <= m; i++)
|
|
a[i] =i;
|
|
for(i = 2; i <= m/2; i++) {
|
|
if(a[i] != 0) {
|
|
for(j=i+i; j <= m; j += i) {
|
|
a[j] = 0;
|
|
}
|
|
}
|
|
}
|
|
for(i = 2; i <= m; i++) {
|
|
if(a[i] != 0) printf("%d\n",a[i]);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|