您的位置:首页 > 其它

题目1040:Prime Number

2013-06-06 22:59 204 查看
http://ac.jobdu.com/problem.php?pid=1040

#include<stdio.h>

#include<math.h>

int a[200005];

void initial()

{

long int i;

int j,count=2;

a[1]=2; a[2]=3;

for(i=4;i<200000;i++){

for(j=2;j<=sqrt(i);j++){ // 第10000个素数是104729,所以要注意求素数的方法,这里用的是sqrt(i)

if(i%j==0) break;

}

if(j>sqrt(i)){

count++;

a[count]=i;

}

}

}

int main()

{

int i,n;

initial();

while(scanf("%d",&n)!=EOF){

printf("%d\n",a
);

}

system("pause");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: