For faster navigation, this Iframe is preloading the Wikiwand page for 素性测试.

素性测试

素性测试素数判定,是检验一个给定的整数是否为素数的测试。

素数

素数是除了自身和1以外,没有其它素数因子的自然数。自从欧几里得证明了有无穷个素数以后,人们就企图寻找一个可以构造所有素数的公式,寻找判定一个自然数是不是素数的方法。因为素数的地位非常重要。

素数判定的历史

鉴别一个自然数是素数还是合数,这个问题在中世纪就引起人们注意,当时人们试图寻找质数公式,到了高斯时代,基本上确认了简单的质数公式是不存在的,因此,高斯认为对素性判定是一个相当困难的问题。从此以后,这个问题吸引了大批数学家。 素性判断算法可分为两大类,确定性算法及随机算法。前者可给出确定的结果但通常较慢,后者则反之。详见以下列表。

确定型算法

  • 试除法(埃拉托斯特尼筛法
    • 尝试从 的整数是否整除
// 以 C 語言實現埃拉托斯特尼篩法
// 用以判斷質數的 is_prime 副函式
int is_prime(int x)
{
    if(x < 2) return 0;            // 1 不是質數,且不考慮負整數與 0,故輸入 x<=1 時回傳 0
    for(int i = 2; i * i <= x; ++i)
        if(x % i == 0) return 0;    // 一旦出現整除,回傳 0
    return 1;                       // 迴圈跑完後都沒有整除,回傳 1
}

随机算法

  • 费马素性检验
  • 米勒-拉宾检验
  • 欧拉-雅科比测试
    • 对于n,挑选随机的,测试,这里为雅可比符号。如果N为素数,等式一定成立;如果N为合数,等式有一半的概率不成立。

参见

外部链接

{{bottomLinkPreText}} {{bottomLinkText}}
素性测试
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?