欧几里得算法(The-Euclidean-Algorithm)

欧几里得算法

在看算法图解时,看到书中的欧几里得的证明有相关连接

当有如下A = B + R ,且B不等于0. 那么就有 GCD(A, B) = GCD(B, A - B)
$ 我们假设C = A - B,那么转为证明GCD(A, B) = GCD(B, C) $
$ \because $ GCD(A, B) 是A,B的最大公因数
$ \therefore $ X GCD(A, B) + Y GCD(A, B) = C
$ \therefore $ (X + Y) GCD(A, B) = C
所以我们可以得知 GCD(A, B) 也是C的因数(但不是最大的)
$ \therefore $ GCD(A, B) $\leq$ GCD(B, C)

$ \because $ C + B = A
$ \therefore $ M GCD(B, C) + N GCD(B, C) = A
$ \therefore $ (M + N) GCD(B, C) = A
所以我们可以得知 GCD(B, C) 也是A的因数(但不是最大的)
$ \therefore $ GCD(B, C) $\leq$ GCD(A, B)

综上 GCD(B, C) = GCD(A, B)

参考链接

The Euclidean Algorithm

Author: Sean
Link: https://blog.whileaway.io/posts/8bf87fd8/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.