Logo

Programming-Idioms

History of Idiom 74 > diff from v45 to v46

Edit summary for version 46 by WHS:
[C++] clarification in comment

Version 45

2020-12-24, 16:23:40

Version 46

2020-12-24, 20:20:52

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
Imports
#include <numeric>
Imports
#include <numeric>
Code
auto x = std::gcd(a, b);
Code
auto x = std::gcd(a, b);
Comments bubble
C++17 or later

Converts a and b to their absolute values
Comments bubble
C++17 or later

Uses the absolute values of a and b in calculations
Doc URL
https://en.cppreference.com/w/cpp/numeric/gcd
Doc URL
https://en.cppreference.com/w/cpp/numeric/gcd