且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

主数生成算法

更新时间:2023-02-26 17:29:37

消除由素数可分割的数字(2,3 ,5,7等)是一个不太糟糕的主意,当你寻找一个(小)素数的列表,但你应该使用新发现的素数,以确保该列表只包含素数(不只是2,3 ,5,7,还有那些通过:11,13,17等)

Eliminating numbers dividable by prime numbers (2,3,5,7 etc.) is a not soo bad idea when you look for a list of (small) prime numbers but you should use the newly found prime numbers too to be sure that the list contains only primes (not only 2,3,5,7 but also those passing: 11,13,17 etc.)

对于更大的素数(你不能计算解释如果数字太大,因为你需要检查几乎所有的数字(说每个4-5无论如何)从1到数字检查),通常的做法是取一个随机大数字,并检查它是否通过 Fermats Small Theorem with say 3,5,7 and 11(IIRC the probability for it it is a non prime if it pass with just

For bigger primes (you just can't calculate the way explained if the numbers are too big as you need to check almost all numbers (say each 4-5 anyhow) from 1 to the number to check), the usual approach is to take a random big number and check if it passes Fermats Small Theorem with say 3,5,7 and 11 (IIRC the probability for it to be a non prime if it passes with just 3,5,7 and 11 is really improbable).

查看 Fermats原始性测试更多的手解释。