Programming-Idioms

History of Idiom 74 > diff from v29 to v30

Edit summary for version 30 :
New Cpp implementation by user [Mnemosynix]

Version 29

2019-09-27, 10:42:00

Version 30

2019-09-28, 16:19:58

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
unsigned long long int GCD(unsigned long long int a, unsigned long long int b)
{
    unsigned long long int c=a%b;
    if(c==0)
        return b;
    return GCD(b, c);
}
Comments bubble
This implementation is the cleanest I know, but it is not meant for negative integers.