主題
Search

最大公約數


最大公約數,有時也稱為最高公約數 (Hardy and Wright 1979, p. 20),是兩個正整數 ab 最大的共同約數,即 ab 都能被它整除。例如,GCD(3,5)=1GCD(12,60)=12,和 GCD(12,90)=6。最大公約數 GCD(a,b,c,...) 也可以定義為三個或更多正整數的最大公約數,即它們共有的最大約數。最大公約數為 1 的兩個或多個正整數被稱為彼此互質,通常簡稱為“互質”。

各種符號約定總結在下表中。

符號來源
GCD(a,b)本作品,Zwillinger (1996, p. 91), Råde and Westergren (2004, p. 54)
gcd(a,b)Gellert et al. (1989, p. 25), D'Angelo and West (1990, p. 13), Graham et al. (1990, p. 103), Bressoud and Wagon (2000, p. 7), Yan (2002, p. 30), Bronshtein et al. (2007, pp. 323-324), Wolfram Language
g.c.d.(a,b)Andrews 1994, p. 22
(a,b)

a, b, ... 的最大公約數在 Wolfram Language 中實現為GCD[a, b, ...].

GreatestCommonDivisor

上圖顯示了 GCD(1,b) 與有理數 b=m/n 的關係。這裡,GCD(r_1,r_2,...) 是最大的有理數 r,對於它,所有的 r_i/r 都是整數。很容易看出,如果 r_i=p_i/q_i,其中 GCD(p_i,q_i)=1,那麼 GCD(r_1,r_2,...)=GCD(p_1,p_2,...)/LCM(q_1,q_2,...)。此外,如果透過將 GCD(1,b) 擴充套件為當 b 是無理數時,其值等於 0,則得到的函式在無理數處連續,在有理數處不連續,並且在任何有限區間上的黎曼積分等於 0。

GCDArray

以上圖表顯示了 GCD(i,j)(i,j)-平面中的一些視覺化表示。左圖是簡單的 GCD(i,j),中間的圖是 GCD(i,j) 的二維離散傅立葉變換的絕對值 (Trott 2004, pp. 25-26),右圖是 1/GCD(i,j) 變換的絕對值。

如果 dab 的最大公約數,那麼 d 是滿足以下條件的最大可能整數

a=dx
(1)
b=dy,
(2)

其中 xy 是正整數。

歐幾里得演算法可以用來求兩個整數的最大公約數,並找到整數 xy 使得

 ax+by=d.
(3)

這個概念也可以推廣到比整數 Z 更一般的。然而,即使對於歐幾里得環,兩個環元素的 GCD 的概念與環的兩個理想的 GCD 概念也不同。當研究除 Z 以外的環(例如多個變數的多項式環)時,這有時會成為混淆的來源。

為了計算 GCD,寫出 ab素因數分解

a=product_(i)p_i^(alpha_i)
(4)
b=product_(i)p_i^(beta_i),
(5)

其中 p_is 是 ab 的所有素因子,並且如果 p_i 沒有在一個因式分解中出現,則相應的指數取為 0。那麼最大公約數 GCD(a,b) 由下式給出

 GCD(a,b)=product_(i)p_i^(min(alpha_i,beta_i)),
(6)

其中 min 表示最小值。例如,考慮 GCD(12,30)

12=2^2·3^1·5^0
(7)
30=2^1·3^1·5^1,
(8)

所以

 GCD(12,30)=2^1·3^1·5^0=6.
(9)

GCD 是可分配的

 GCD(ma,mb)=mGCD(a,b)
(10)
 GCD(ma,mb,mc)=mGCD(a,b,c),
(11)

且是結合性的

GCD(a,b,c)=GCD(GCD(a,b),c)
(12)
=GCD(a,GCD(b,c))
(13)
GCD(ab,cd)=GCD(a,c)GCD(b,d)×GCD(a/(GCD(a,c)),d/(GCD(b,d)))×GCD(c/(GCD(a,c)),b/(GCD(b,d))).
(14)

如果 a=a_1GCD(a,b)b=b_1GCD(a,b),則

GCD(a,b)=GCD(a_1GCD(a,b),b_1GCD(a,b))
(15)
=GCD(a,b)GCD(a_1,b_1),
(16)

所以 GCD(a_1,b_1)=1。GCD 也是冪等的

 GCD(a,a)=a,
(17)

交換律

 GCD(a,b)=GCD(b,a),
(18)

並滿足吸收律

 LCM(a,GCD(a,b))=a.
(19)
GCDRecurrence

對於正奇數 ab,收斂到 GCD(a,b) 的遞迴方程由下式給出

 x_n=(x_(n-1)+x_(n-2))/(2^(gde(x_(n-1)+x_(n-2),2)))
(20)

其中 x_1=ax_2=b,其中 gde(n,b)bn 中的最大整除指數 (Stehlé and Zimmerman 2004)。上圖顯示了奇數 1<=a,b<=199 收斂所需的迭代次數。

隨機選擇的兩個整數互質的機率為 [zeta(2)]^(-1)=6/pi^2,其中 zeta(z)黎曼 zeta 函式。Polezzi (1997) 觀察到 GCD(m,n)=k,其中 k平面上連線向量 (0, 0) 和 (m,n) 的直線上的格點數(不包括 (m,n) 本身)。這個觀察結果與獲得互質整數的機率密切相關,也與既約分數 y/x 的幾何解釋有關,即作為穿過格點的字串,端點為 (1,0) 和 (x,y)。它壓在 (x_i,y_i) 上的釘子給出了 y_i/x_i 的交替收斂項,是 y/x連分數,而其他收斂項是從它壓在釘子上獲得的,初始端點為 (0, 1)。

Knuth 證明了

 GCD(2^p-1,2^q-1)=2^(GCD(p,q))-1.
(21)

另請參閱

Bézout 數, Bézout 定理, 狄利克雷函式, 歐幾里得果園, 歐幾里得演算法, 擴充套件最大公約數, 高斯引理, 最大公約數定理, 半 GCD, 最小公倍數, 最小素因子, 果園種植問題, 互質, 大衛之星定理 在 課堂中探索此主題

相關 Wolfram 網站

http://functions.wolfram.com/IntegerFunctions/GCD/

使用 探索

參考文獻

Andrews, G. E. Number Theory. New York: Dover, 1994.Bressoud, D. M. and Wagon, S. A Course in Computational Number Theory. London: Springer-Verlag, 2000.Bronshtein, I. N.; Semendyayev, K. A.; Musiol, G.; and Muehlig, H. Handbook of Mathematics, 5th ed. Berlin: Springer-Verlag, 2007.D'Angelo, J. P. and West, D. B. Mathematical Thinking: Problem-Solving and Proofs, 2nd ed. Upper Saddle River, NJ: Prentice-Hall, 2000.Gellert, W.; Gottwald, S.; Hellwich, M.; Kästner, H.; and Künstner, H. (Eds.). VNR Concise Encyclopedia of Mathematics, 2nd ed. New York: Van Nostrand Reinhold, 1989.Graham, R. L.; Knuth, D. E.; and Patashnik, O. Concrete Mathematics: A Foundation for Computer Science. Reading, MA: Addison-Wesley, 1990.Nagell, T. "Least Common Multiple and Greatest Common Divisor." §5 in Introduction to Number Theory. New York: Wiley, pp. 16-19, 1951.Polezzi, M. "A Geometrical Method for Finding an Explicit Formula for the Greatest Common Divisor." Amer. Math. Monthly 104, 445-446, 1997.Råde, L. and Westergren, B. Mathematics Handbook for Science and Engineering. Berlin: Springer-Verlag, 2004.Séroul, R. "The Greatest Common Divisor." §2.4 in Programming for Mathematicians. Berlin: Springer-Verlag, pp. 9-11, 2000.Stehlé, D. and Zimmerman, P. "A Binary Recursive GCD Algorithm." In Algorithmic Number Theory. Proceedings of the 6th International Symposium (ANTS-VI) held at the University of Vermont, Burlington, VT, June 13-18, 2004 (Ed. D. Buell). Berlin: Springer-Verlag, pp. 411-425, 2004.Trott, M. The Mathematica GuideBook for Programming. New York: Springer-Verlag, pp. 25-26, 2004. http://www.mathematicaguidebooks.org/.Yan, S. Y. Number Theory for Computing, 2nd ed. Berlin: Springer, 2002.Zwillinger, D. (Ed.). "Greatest Common Divisor." §2.3.5 in CRC Standard Mathematical Tables and Formulae, 30th ed. Boca Raton, FL: CRC Press, p. 91, 1996.

在 中被引用

最大公約數

引用為

Weisstein, Eric W. "最大公約數。" 來自 Web 資源。 https://mathworld.tw/GreatestCommonDivisor.html

主題分類