如何找到一个黄金没有不使用我的函数CHK黄金,因为我希望我的优化算法中 [英] How to find a prime no without using my function chk prime as i wish to optimize my algo
问题描述
得到long long int chkPrime(长长整型Z)
{
INT I; 如果(Z == 1)
返回0; 如果(Z == 2)
返回1; 对于(i = 2; I< = Z / 2;我++)
如果(!(Z%I))
返回0;
返回1;
}
如果你想检查是否一定数量绝对是素数,最快的(即多项式运行时)确定的算法是的 AKS测试(维基百科) AFAIK。
如果你想为在一定范围内建立的素数,你应该看看筛分(维基百科),或者像我会建议从网上下载他们作为列表(例如这里< /一>用于第一10000)
在筛分维基百科的文章中提到两个很好的概率素性测试,所以我就不提了。测试不但是只能说一个数是否是素以大概率(所谓素数可能)。
long long int chkPrime(long long int z)
{
int i;
if(z==1)
return 0;
if(z==2)
return 1;
for(i=2;i<=z/2;i++)
if(!(z%i))
return 0;
return 1;
}
If you want to check if a certain number is definitely prime, the fastest (i.e. polynomial runtime) deterministic algorithm is the AKS-test(Wikipedia) afaik.
If you want to create primes for a certain range, you should look at sieving(Wikipedia), or, as I would recommend download them as list from the internet (e.g. here for the first 10000).
The wikipedia article on sieving mentions two good probabilistic primality test, so I will not mention any more. The test does however only say whether a number is a prime with a large probability (so called probable primes).
这篇关于如何找到一个黄金没有不使用我的函数CHK黄金,因为我希望我的优化算法中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!