这样做倒是挺简单的,怎么容易怎么做
#include<stdio.h> #include<string.h> #define maxn 1000000 int isprime[maxn+10]; int prime[maxn/10]; int count; int n; int main() { while(scanf("%d",&n)!=EOF) { count=0; for(int i=0;i<=maxn+10;i++) isprime[i]=0; for(int i=2; i<=n; i++) { if(isprime[i]==0) { prime[count++]=i; for(int j=i; j<=n; j+=i) isprime[j]=1; } } printf("%d\n",count); } return 0; }
原文:http://www.cnblogs.com/calmwithdream/p/4934598.html