An efficient solution is provided here for reference.
Note that the second line of the program GCD function returns another value when one of the values is 0. Otherwise, stack overflow occurs (because there is no non-recursive ending condition !)
The Code is as follows:
// Programming: USD 2.7 Max. Public approx. <br/> # include <iostream> <br/> using namespace STD; <br/> template <class T> <br/> T gcd (t x, t y) <br/> {<br/> If (x <Y) <br/> return gcd (Y, x); <br/> If (! Y) <br/> return X; <br/> If (X & static_cast <t> (1) = 0) // X is even <br/>{< br/> If (Y & static_cast <t> (1) = 0) <br/>{< br/> return 2 * gcd (x> 2, Y> 2 ); <br/>}< br/> else <br/>{< br/> return gcd (x> 2, y ); <br/>}< br/> else <br/> {<br/> If (Y & static_cast <t> (1) = 0) <br/>{< br/> return gcd (X, Y> 2); <br/>}< br/> else return gcd (x-y, y ); <br/>}< br/> int main () <br/>{< br/> while (1) <br/>{< br/> int A = ABS (RAND (); <br/> int B = ABS (RAND ()); <br/> cout <A <"" <B <":" <gcd (a, B) <Endl; <br/>}< br/> return 0; <br/>}