// To determine m that is relatively prime to n. m = 2; while( gcd( n, m ) != 1 ) { m = m + 1; } // This method determines the Greatest Common Divisor of a and b // using Euclid's algorithm. public static int gcd( int a, int b ) { int temp; while( b > 0 ) { if( b > a ) { temp = a; a = b; b = temp; } else { a = a - b; } } return a; }