private IntegerPolynomial MultRecursive(IntegerPolynomial Factor) { int[] a = Coeffs; int[] b = Factor.Coeffs; int n = Factor.Coeffs.Length; if (n <= 32) { int cn = 2 * n - 1; IntegerPolynomial c = new IntegerPolynomial(new int[cn]); for (int k = 0; k < cn; k++) { for (int i = Math.Max(0, k - n + 1); i <= Math.Min(k, n - 1); i++) c.Coeffs[k] += b[i] * a[k - i]; } return c; } else { int n1 = n / 2; IntegerPolynomial a1 = new IntegerPolynomial(a.CopyOf(n1)); IntegerPolynomial a2 = new IntegerPolynomial(a.CopyOfRange(n1, n)); IntegerPolynomial b1 = new IntegerPolynomial(b.CopyOf(n1)); IntegerPolynomial b2 = new IntegerPolynomial(b.CopyOfRange(n1, n)); // make a copy of a1 that is the same length as a2 IntegerPolynomial A = new IntegerPolynomial(a1.Coeffs.CopyOf(a2.Coeffs.Length)); A.Add(a2); // make a copy of b1 that is the same length as b2 IntegerPolynomial B = new IntegerPolynomial(b1.Coeffs.CopyOf(b2.Coeffs.Length)); B.Add(b2); IntegerPolynomial c1 = a1.MultRecursive(b1); IntegerPolynomial c2 = a2.MultRecursive(b2); IntegerPolynomial c3 = A.MultRecursive(B); c3.Subtract(c1); c3.Subtract(c2); IntegerPolynomial c = new IntegerPolynomial(2 * n - 1); for (int i = 0; i < c1.Coeffs.Length; i++) c.Coeffs[i] = c1.Coeffs[i]; for (int i = 0; i < c3.Coeffs.Length; i++) c.Coeffs[n1 + i] += c3.Coeffs[i]; for (int i = 0; i < c2.Coeffs.Length; i++) c.Coeffs[2 * n1 + i] += c2.Coeffs[i]; return c; } }