Inbuilt __gcd(A,B) function in C++

Names starting with two underscores are reserved for the implementation, which means that you are not allowed to define such names in your code, and there are no standard guarantees what those names mean if they do exist. However, a vendor might choose to document some such names, in which case you can use them with the product for which the vendor documents them.


In C++17 there are standard library functions for GCD and LCM.

#include <iostream>
#include <numeric>

int main ()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << std::gcd(a,b) << '\n';
    return (0);
}

Tags:

C++