/**
  * Euclid's greatest common divisor algorithm.
  * Find the largest number that evenly divides into both n and d.
  * require: n >= 0, d >= 0.
  * fastest if n >= d.
  */
public static int gcd(int n, int d)
   {
   if ( d == 0 )
      {
      return 1;
      }
   int r = n % d;
   return( r == 0 ) ? d : gcd( d , r );
   }