一道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/06/22 16:09:19
![一道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](/uploads/image/z/7147084-4-4.jpg?t=%E4%B8%80%E9%81%93ACM%E6%B0%B4%E9%A2%98%2C%E8%BF%98%E5%8F%AF%E4%BB%A5%E6%80%8E%E4%B9%88%E7%AE%80%E5%8C%96%E5%91%A2%3FDescriptionA+prime+number+is+a+natural+number+which+has+exactly+two+distinct+natural+number+divisors%3A1+and+itself.The+first+prime+number+is+2.Can+you+write+a+program+that+computes+the+nth+prime+number%2Cgiven+a)
一道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