class Gcd { public static int gcd( int m, int n ) { System.out.println( "finding gcd("+m+","+n+")" ); if( n==0 || m==0 ) return 0; else if ( m < n ) // always want n to be smaller return gcd(n,m); else if( m%n == 0 ) // if n evenly divides m, n is GCD return n; else // reduce the problem return gcd(n,m%n); } public static void main( String[] args ) { boolean done; do { int x, y; x = Stdin.getInt(); y = Stdin.getInt(); int g = gcd( x, y ); System.out.print ( "GCD("+x+","+y+") = " ); System.out.println( g ); done = ( x==0 && y==0 ); } while( !done ); } }