The Greatest Common Divisor in Mathematics is abbreviated to GCD. This number represents the largest value that has the ability to divide the two given numbers completely. It is also referred to as the greatest common factor or GCF in few cases. Let us consider an example of two numbers, 12 and 28. The numbers that can divide both of these numbers are 2 and 4. However, ‘4’ is the greatest number that can divide both 12 and 24 completely. Hence, the GCD of 12 and 24 is 4. The GCD can be found for any number of inputs. It is just the common largest number that can divide all the input numbers. Finding GCD of a number finds a wide range of applications in encryption technology. It is also used in the simplification of fractions.
A built-in function exists in the Python interpreter’s math module that can compute the GCD of any two input numbers. This inbuilt function is the GCD() function. The gcd() function in Python accepts two parameters of integer type and returns an integer that is equivalent to the GCD value of the two input parameters.
The general syntax of the gcd() function in Python is:
The gcd() function in Python returns a positive integer whose value is equivalent to the greatest common divisor of the input parameters.
Apart from using the gcd() function, there are several other methods and approaches to determine the GCD of two numbers in Python. The approaches include:
Determining GCD using recursions
Finding GCD using loops
Implementation of GCD using Euclidean Algorithm
You can learn both theoretical and practical aspects of Python with upGrad’s Professional Certificate in Data Science and Business Analytics from the University of Maryland. This course helps you learn Python from scratch. Even if you are new to programming and coding, upGrad will offer you a two-week preparatory course so that you can pick up on the basics of programming. you will learn about various tools like Python, SQL,, while working on multiple industry projects.