题目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;
}
#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;
}
相关文章推荐
- 题目1040:Prime Number
- 【九度】题目1040:Prime Number
- 题目1040:Prime Number
- 【九度OJ】题目1040:Prime Number 解题报告
- 题目1040:Prime Number
- JD 题目1040:Prime Number (筛法求素数)
- 九度题目1040:Prime Number
- 题目 1040 Prime Number 九度Online Judge
- 题目1040:Prime Number
- 题目1040:Prime Number
- 题目1040:Prime Number
- 题目1040:Prime Number(第k个素数)
- 题目1040:Prime Number(素数的生成)
- 题目1040:Prime Number
- 题目1040:Prime Number 题目1047:素数判定
- 题目1040:Prime Number
- 九度OJ题目1040:Prime Number
- 九度 oj 题目1040:Prime Number
- 52-题目1040:Prime Number
- 题目1040:Prime Number