Java program for the above approach
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int GCD ( int a , int b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; }