Пример #1
0
 public static GcdLong gcd(long[] xs, int nx, long[] ys, int ny) {
   nx = highest(xs, 0, nx);
   ny = highest(ys, 0, ny);
   if (nx == 0 || ny == 0) {
     throw new IllegalArgumentException(dividesByZero("x or y"));
   } else if (nx < ny) {
     long[] zs = xs;
     int nz = nx;
     xs = ys;
     nx = ny;
     ys = zs;
     ny = nz;
   }
   while (0 < ny) {
     int nr = Euclid.divides(xs, nx, ys, ny);
     long[] rs = xs;
     nr = highest(rs, 0, nr);
     // Arrays.fill(rs, nr, nx, 0);
     xs = ys;
     nx = ny;
     ys = rs;
     ny = nr;
   }
   return new GcdLong(xs, nx);
 }
Пример #2
0
 public static GcdFraction gcd(long[] xs0, long[] xs1, int nx, long[] ys0, long[] ys1, int ny) {
   nx = highest(xs0, 0, nx);
   ny = highest(ys0, 0, ny);
   if (nx == 0 || ny == 0) {
     throw new IllegalArgumentException(dividesByZero("x or y"));
   } else if (nx < ny) {
     long[] zs0 = xs0;
     long[] zs1 = xs1;
     int nz = nx;
     xs0 = ys0;
     xs1 = ys1;
     nx = ny;
     ys0 = zs0;
     ys1 = zs1;
     ny = nz;
   }
   while (0 < ny) {
     int nr = Euclid.divides(xs0, xs1, nx, ys0, ys1, ny);
     long[] rs0 = xs0;
     long[] rs1 = xs1;
     nr = highest(rs0, 0, nr);
     // Arrays.fill(rs0, nr, nx, 0);
     xs0 = ys0;
     xs1 = ys1;
     nx = ny;
     ys0 = rs0;
     ys1 = rs1;
     ny = nr;
   }
   return new GcdFraction(xs0, xs1, nx);
 }