Greatest Common Divisor
In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that is a divisor of both numbers. For example, the GCD of 8 and 12 is 4.
The greatest common divisor is also known as the greatest common factor (gcf), highest common factor (hcf), greatest common measure (gcm), or highest common divisor.
Example :
What is the greatest common divisor of 54 and 24?
The number 54 can be expressed as a product of two integers in several different ways:
Thus the divisors of 54 are: 1, 2, 3, 6, 9, 18, 27, 54
Similarly, the divisors of 24 are: 1, 2, 3, 4, 6, 8, 12, 24
The numbers that these two lists share in common are the common divisors of 54 and 24:
1, 2, 3, 6 .
The greatest of these is 6. That is, the greatest common divisor of 54 and 24. One writes:
SOURCE CODE : :
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer