In many competitive programming problems, we need to find greatest common divisor also known as gcd. Euclids algorithm to find gcd has been discussed here
C++ has the built-in function for calculating GCD. This function is present in
__gcd(m, n) Parameter : m, n Return Value : 0 if both m and n are zero, else gcd of m and n.
gcd(6, 20) = 2
Note: If either M or N is not an integer type, or if either is (possibly cv-qualified) bool, the program is ill-formed. Also, If either |m| or |n| is not representable as a value of type std::common_type_t
Error, As the data type float is not supported by std::gcd.
This article is contributed by Pratik Chhajer. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Inbuilt function for calculating LCM in C++
- Rearrange positive and negative numbers using inbuilt sort function
- Finding Floor and Ceil of a Sorted Array using C++ STL
- Finding the Parity of a number Efficiently
- Finding inverse of a matrix using Gauss - Jordan Method | Set 2
- Finding Median of unsorted Array in linear time using C++ STL
- Array with GCD of any of its subset belongs to the given array
- What happens when a virtual function is called inside a non-virtual function in C++
- Function Overloading vs Function Overriding in C++
- Difference between Virtual function and Pure virtual function in C++
- How to call function within function in C or C++
- Difference between virtual function and inline function in C++
- Can we call an undeclared function in C++?
- Can we use function on left side of an expression in C and C++?
- Declare a C/C++ function returning pointer to array of integer pointers
- Function overloading and return type
- Default arguments and virtual function
- Function overloading and const keyword
- How to measure time taken by a function in C?
- Comparator function of qsort() in C