一道ACM水题,还可以怎么简化呢?DescriptionA 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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 07:12:40
一道ACM水题,还可以怎么简化呢?DescriptionA 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
一道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
一道ACM水题,还可以怎么简化呢?DescriptionA 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
传统法优化后.
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