一道ACM水题,还可以怎么简化呢?

问题描述:

一道ACM水题,还可以怎么简化呢?
Description
A prime number is a natural number which has exactly two distinct natural number divisors:1 and itself.The first prime number is 2.Can you write a program that computes the nth prime number,given a number n
1个回答 分类:英语 2014-09-23

问题解答:

我来补答
传统法优化后.
int prime(int n)
{
int i;
double t;
if(n%2!=0 || n==2)
{
if(n==2)
return 1;
else
{
t=sqrt(n); //#include
for(i=3;it)
return 1;
else
return 0;
}
}
else
return 0;
}
埃拉托斯特尼筛子法做预处理:
int i,j,a[10001];
for(i=0;i
 
 
展开全文阅读
剩余:2000
下一页:请说清为什么