Logo

Programming-Idioms

History of Idiom 74 > diff from v42 to v43

Edit summary for version 43 by programming-idioms.org:
Restored version 39: New implementation => not overwrite existing one please

Version 42

2020-11-23, 19:59:32

Version 43

2020-11-23, 20:00:11

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.

Variables
x,a,b
Variables
x,a,b
Code
gcd a b
    |   a==b =a
    |   a>b = gcde(a-b) b
    |   otherwise = gcde a (b-a)
Code
x = gcd a b