欧几里得算法:最大公因数 ( g c d ) (gcd) (gcd)
该算法基于:
g c d ( a , b ) = g c d ( b , a gcd(a,b)=gcd(b,a gcd(a,b)=gcd(b,a% b ) b) b)
证明:
令 a a a % b = r b = r b=r,
则 a = k ? b + r , a = k * b + r, a=k?b+r,
因此 r = a ? k
该算法基于:
g c d ( a , b ) = g c d ( b , a gcd(a,b)=gcd(b,a gcd(a,b)=gcd(b,a% b ) b) b)
证明:
令 a a a % b = r b = r b=r,
则 a = k ? b + r , a = k * b + r, a=k?b+r,
因此 r = a ? k