首页
社区
课程
招聘
求最大公约数(辗转相除法)算法的证明
发表于: 2009-9-5 09:48 11647

求最大公约数(辗转相除法)算法的证明

2009-9-5 09:48
11647

很多人都知道这个算法,但怎样得来的可能知道的不多,在此翻译一篇与大家共享:科普一下
辗转相除法主要就是采用了公式GCD(a, b) = GCD(b, a mod b)  假设a>=b
GCD 是Greatest common divisor的缩写即最大公约数。
For any nonnegative integer a and any positive integer b, GCD(a, b) = GCD(b, a mod b). Proof We shall show that GCD(a, b) and GCD(b, a mod b) divide each other, so that by equation (31.5) they must be equal (since they are both nonnegative).对于任何非负整数a和任意正数b,等式GCD(a, b) = GCD(b, a mod b) 成立。证明:通过GCD(a, b) 和GCD(b, a mod b)可以彼此相除,利用等式31.5可知它们相等(GCD(a, b)不可能为- GCD(b, a mod b),因为它们都是非负数)。
注:We have that n | a if and only if a mod n = 0.
    如果 a mod n = 0 我们就称作n | a   “ |” 读作divide
We first show that GCD(a, b) | GCD(b, a mod b). If we let d = GCD(a, b), then d | a and d | b. By equation (3.8), (a mod b) = a - qb, where q为a/b 向下取整. Since (a mod b) is thus a linear combination of a and b, equation (31.4) implies that d | (a mod b). Therefore, since d | b and d | (a mod b), Corollary 31.3 implies that d | GCD(b, a mod b) or, equivalently, that   GCD(a, b) = GCD(b, a mod b)  (31.14)
首先证明GCD(a, b) | GCD(b, a mod b).令d = GCD(a, b),由最大公约数的定义可知
d | a 和 d | b成立,即d | qb也成立。由等式3.8,可知a mod b 是a和b的线性组合a - qb,再由31.4得到d | (a - qb)即d | (a mod b),由前面的d | b结合推论31.3可知 d | GCD(b, a mod b) 即GCD(a, b) | GCD(b, a mod b) (31.14)成立。
Showing that GCD(b, a mod b) | GCD(a, b) is almost the same. If we now let d = GCD(b, a mod b), then d | b and d | (a mod b). Since a = qb + (a mod b), where q = a/b, we have that a is a linear combination of b and (a mod b). By equation (31.4), we conclude that d | a. Since d | b and d | a, we have that d | GCD(a, b) by Corollary 31.3 or, equivalently, that GCD(b, a mod b) | GCD(a, b)  (31.15)
同理证明(31.15) GCD(b, a mod b) | GCD(a, b)

Using equation (31.5) to combine equations (31.14) and (31.15) completes the proof. 由等式31.5结合(31.14)、 (31.15) 证明GCD(a, b) = GCD(b, a mod b)成立。

equation (3.8)  a mod n=a- q*n  q为a/n 向下取整
(31.3) d | a and d | b implies  d | (a+b) and d | (a-b)
More generally, we have that  
(31.4) d | a and d | b  implies  d | (ax+by)  for any integers x and y.
Also, if a | b, then either |a| <=|b| or b = 0, which implies that
(31.5) a | b and b | a  implies a=±b
推论Corollary 31.3
For any integers a and b, if d | a and d | b then d | GCD(a, b).
Proof This corollary follows from equation (31.4), because GCD(a, b) is a linear combination of a and b by Theorem 31.2.
Theorem 31.2  GCD(a, b)是a和b的一个线性组合
证明 a和b的最大公约数GCD(a, b)等于线性组合ax + by组成的元素集合中的最小正数值。
If a and b are any integers, not both zero, then GCD(a, b) is the smallest positive element of the set {ax + by : x, y为 Z} of linear combinations of a and b.
Proof Let s be the smallest positive such linear combination of a and b, and let
s = ax + by for some x, y Z. Let q 为 a/s向下取整.Equation (3.8)
a mod s = a - qs = a - q(ax + by) = a (1 - qx) + b(-qy),
and so a mod s is a linear combination of a and b as well. But, since a mod s < s, (注:a mod s 是a、b的线性组合,s也是a、b的线性组合且已经是最小的正数,那么a mod s 由定义必须>=0,因此只能是0),we have that a mod s = 0(即s是a的一个因子). Therefore, s | a and, by analogous reasoning,同理 s | b. Thus, s is a common divisor of a and b即s是a,b的一个公约数, and so GCD(a, b)>= s. Equation (31.4) implies that GCD(a, b) | (ax + by), since GCD(a, b) divides both a and b and s is a linear combination of a and b,so GCD(a, b) | s, and s > 0 imply that GCD(a, b) <=s. Combining GCD(a, b)>=s and GCD(a, b) <=s yields GCD(a, b) = s; we conclude that s is the greatest common divisor of a and b.得出结论a,b的最大公约数就是s,也就是说a,b的最大公约数就是线性组合ax + by组成的元素集合中的最小正数值。

                                                         2009.9.5 天易love


[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 7
支持
分享
最新回复 (11)
雪    币: 251
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
可怜,被和谐了
估计楼主没想到会被和谐,等被和谐了,才知道和谐无处不在
2009-9-5 10:02
0
雪    币: 328
活跃值: (34)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
哈哈!有点意思,“GCD”也被和谐了...
2009-12-17 14:22
0
雪    币: 266
活跃值: (204)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
真的 GCD 也和谐啊
2010-7-18 13:13
0
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
5
http://zh.wikipedia.org/zh/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95
2010-7-19 00:37
0
雪    币: 82
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
这个算法貌似是中国古人发现的
2010-7-20 13:26
0
雪    币: 122
活跃值: (44)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
这个找个数论方面的书都会有的
2010-7-20 22:39
0
雪    币: 2015
活跃值: (902)
能力值: ( LV12,RANK:1000 )
在线值:
发帖
回帖
粉丝
8
楼上莫非是数论老师?forgot前辈给的网址不错
2010-7-21 06:15
0
雪    币: 358
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
欧几里得 发明的
2010-7-22 09:06
0
雪    币: 200
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
这是数论上的证明方法吧,高代上不是这么证的,不过差不多。
2010-7-22 09:25
0
雪    币: 459
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
GCD,和谐了。哈哈
2010-7-30 18:13
0
雪    币: 2993
活跃值: (25)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
12
这个算法现在被人教社引进高中数学课本了,我刚刚考完高考
2010-8-2 11:32
0
游客
登录 | 注册 方可回帖
返回
//