GCD is the greatest common divisor. pseudo-code:

function Euclid(x,y)

if y==0 return x;

return Euclid(y, x MOD y).

correctness:

Euclid's rule: If x and y are positive integers with x >= y, then gcd(x, y) = gcd(x mod y, y).

Prove: just to prove gcd(x, y) = gcd(x-y, y). Let GCD is k, then if k can divide x and y, then k can also divide x-y, so gcd(x, y) <= gcd(x-y, y). On the other hand, if k can divide x-y and y, then k can also divide x, so gcd(x, y) >= gcd(x-y, y). Thus the rule is proved.

running time:O( n3)

相关文章:

  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-10-18
  • 2022-12-23
  • 2021-09-30
猜你喜欢
  • 2022-12-23
  • 2021-10-24
  • 2021-07-15
  • 2022-01-17
  • 2021-12-13
  • 2021-09-04
  • 2022-01-11
相关资源
相似解决方案