An algorithm isn't necessary in this case. The factors of 4 are 1, 2 and 4 and the factors of 6 are 1, 2, 3 and 6. Just by looking at them we can tell that the common factors are 1 and 2 and that the greatest of these is 2.
GCD(4, 5) = 1.
GCD: 4
The Greatest Common Divisor (GCD) for 4 20 is 4
since 14 = 14 x 1 and 56 = 14 x 4 the answer is 14, since it divides evenly into both and clearly nothing larger will.There is a clever algorithm that can help you work this out in the general case:GCD(14, 56) = GCD(14, 56 - 14) = GCD(14, 42)This step (subtract the smaller from the larger) relies on the fact that any number that divides both 14 and 56 also divides 56 - 14.Repeat this:GCD(14, 42) = GCD(14, 42 - 14) = GCD(14, 28)GCD(14, 28) = GCD(14, 28 - 14) = GCD(14, 14)which is clearly 14.This is called Euclid's Algorithm.
Greatest Common Divisor (GCD) for 12 8 is 4.
GCD(12, 40) = 4
4
two
The LCM of any two numbers can be found with the following formula:LCM(a,b) = (ab) / GCD (a,b).The GCD of two numbers is best found with the Euclidean algorithm which is as follows:GCD(a,b) =a --if b = 0or GCD(b, a mod b) otherwiseIn the example given we have GCD(42,7) = GCD(7, 0) = 7Then LCM(42,7) = (7*42)/7 = 42Note: mod is the operation of dividing one number by another and taking the remainder. e.g. 7 mod 4 = 3, 12 mod 6 = 0.
Greatest Common Divisor (GCD) for 8 28 is 4.
The Greatest Common Divisor (GCD) for 36 100 is 4
The Greatest Common Divisor (GCD) for 36 20 is 4.