Logo

Programming-Idioms

History of Idiom 74 > diff from v28 to v29

Edit summary for version 29 by derSteFfi:
New C implementation by user [derSteFfi]

Version 28

2019-09-27, 08:08:26

Version 29

2019-09-27, 10:42:00

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
#include <gmp.h>
Code
mpz_t _a, _b, _x;
mpz_init_set_str(_a, "123456789", 10);
mpz_init_set_str(_b, "987654321", 10);
mpz_init(_x);

mpz_gcd(_x, _a, _b);
gmp_printf("%Zd\n", _x);
Doc URL
https://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions