/Eculid-GCD

Euclidean algorithm to calculates the greatest common divisor (GCD) in Python

Primary LanguagePython

Eculid-GCD

Euclidean algorithm to calculates the greatest common divisor (GCD) in Python for two numbers.

Euclid's algorithm: Given two positive number m and n (m > n), find their greatest common divisor. i.e., the largest positive integer which evenly divide both m and n.

  • step_1 [Find Remainder.] : Divide m by n and let r be the remainder(0 <= r < n).
  • step_2 [Is remainder 0] : if r = 0, the algorithm terminates; n is the answer.
  • step_3 [Interchange] : set m <- n, n <- r, and go back to step 1.