Logo

Programming-Idioms

History of Idiom 74 > diff from v27 to v28

Edit summary for version 28 by daxim:
New Perl implementation by user [daxim]

Version 27

2019-09-26, 16:39:11

Version 28

2019-09-27, 08:08:26

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.

Imports
use bigint;
Code
sub gcd {
    my ($A, $B) = @_;
    return 0 == $B
        ? $A
        : gcd($B, $A % $B);
}
Doc URL
http://p3rl.org/bigint