Logo

Programming-Idioms

History of Idiom 74 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-22, 15:43:17

Version 6

2015-08-22, 22:59:47

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #74 Compute GCD

Compute the greatest common divisor x of big integers a and b. Use an integer type able to handle huge numbers.

Code
function GCD(a,b:int64):int64;

var t:int64;

begin
  while b <> 0 do
    begin
       t := b;
       b := a mod b;
       a := t;
    end;
    result := a;
end;
Comments bubble
Using the Euklid Algorithm
Origin
https://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations