标签:san 输入 font lin 数据 输出 上传 file math.h
5 10 11 0
2 3 5 2 3 5 7 2 3 5 7 11
素数打表。提交開始超时。改成c语言的就过了
#include<iostream> #include<string.h> #include<math.h> #include<stdio.h> using namespace std; int a[2000001]; void sushu() { int i,j; a[0]=a[1]=1; for(i=2;i<=sqrt(2000000);i++) { if(a[i]==0) { for(j=i*i;j<=2000000;j+=i) { a[j]=1; } } } } int main() { sushu(); int N,i,time; while(scanf("%d",&N) && N) { time=0; if(N>=2) printf("2"); for(i=3;i<=N;i++) { if(a[i]==0) //cout<<" "<<i; printf(" %d",i); } cout<<endl; } return 0; }
标签:san 输入 font lin 数据 输出 上传 file math.h
原文地址:http://www.cnblogs.com/yxysuanfa/p/7008733.html