Given two non-negative integers a & b. Find the GCD (greatest common divisor), i.e., the largest number which is a divisor of both a & b. It’s commonly denoted by gcd(a,b).
From min(A, B) to 1, we can traverse over all the numbers and determine if the current number divides both A & B or not. If it does, then it will be the GCD of A and B.
Subtract smaller numbers from larger ones when we want to reduce larger numbers. It does not change GCD. Alternatively, we can divide the smaller number & the algorithm stops when the remainder=0.