Logo

Programming-Idioms

History of Idiom 74 > diff from v41 to v42

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

Version 41

2020-11-23, 04:50:16

Version 42

2020-11-23, 19:59:32

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 = gcd(a-b) b
    |   otherwise = gcd a (b-a)
Code
gcd a b
    |   a==b =a
    |   a>b = gcde(a-b) b
    |   otherwise = gcde a (b-a)