Euclid 规则:如果x 和 y 是正整数,且有x≥y,那么gcd(x, y) = gcd(x mod y, y)。
证明:待续
function Euclid(a, b)
Input: Two integers a and b with a > 0 and b > 0
Output: gcd(a, b)
if b = 0: return a
return Euclid(b, a mod b)
引理:对于任意的正整数a 和 b,利用扩展Euclid算法可以求得整数x, y 和 d,使得 gcd(a, b) = d = ax + by 成立。
function extend-Euclid(a, b)
Input: Two positive integers a and b with a > 0 and b > 0
Output: Integers x, y, d such that d = gcd(a, b) and ax + by = d
if b = 0: return (1, 0, a)
(x', y', d) = extend-Euclid(b, a mod b)
return (y', x'- [a/b]y', d)
注:[]为向下取整
证明:待续
相关题目:pku 1061 青蛙的约会 http://acm.pku.edu.cn/JudgeOnline/problem?id=1061
解题报告:待续
本文介绍了欧几里得算法及其扩展版本,用于求解两个正整数的最大公约数,并提供了一种方法来找到使等式gcd(a,b)=d=ax+by成立的整数x和y。
1644

被折叠的 条评论
为什么被折叠?



