//......................................................................... //------------------------------------------------------------------------- //------MORE EFFICIENT PROGRAM TO FINd GCD OF TWO POSITIVE INTEGERS-------- //-----------------------THE JAVA CODE STARTS HERE------------------------- //--------THE DEVELOPMENT OF ALGORITHM IS GIVEN AT THE END----------------- //......................................................................... cclass gcd2 { public static void main(String args[]) { long num1 = 1007199254740998L; long num2 = 42; long small,big; // variables to manipulate num1 and num2 small = num1; big = num2; long temp=0; // in order to ensure that small<=big, we execute the following // if statement if(small>big) { temp = small; small = big; big = temp; } // at this stage small<=big. We now write the iterative code for // computing the gcd of the two numbers. while(big%small!=0) { temp = big%small; big = small; small=temp; } System.out.println(" GCD of "+num1+" and "+num2+" is : "+small); } } //......................................................................... //...............THE DEVELOPMENT OF THE ALGORITHM IS GIVEN BELOW........... //......................................................................... // Having realized that gcd1.java is a correct but an inefficient program, // we need to design efficient algorithm for finding GCD of two numbers. // We start with the following simple Theorem which you might have seen in // your high school. // ....................................................................... // Theorem : For any two positive integers x and y, there exist two unique // integers r and d such that // x = r*y + d, where d