title: Calculating the product of BigInteger[]
body: <p>Context: I'm trying to calculate factorials for very large n  using the BigInteger class in Java (for n>100,000) and so far this what I'm doing:</p>
  
  <ul>
  <li><p>Produce all primes less than or equal to n using Sieve of Erasthones</p></li>
  <li><p>Find to which powers they will be raised.</p></li>
  <li><p>Raise all the numbers to the respective powers.</p></li>
  <li><p>Use a divide and conquer recursive method to multiply them all.</p></li>
  </ul>
  
  <p>From the research I've done on the internet, this is asymptotically faster than simply multiplying all k up to n. However I've noticed that the slowest part of my implementation is the part where I multiply all the prime powers. My questions are:</p>
  
  <ul>
  <li>Is there a faster way to calculate the product of lots of numbers?</li>
  <li>Can my implementation be improved ?</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>public static BigInteger product(BigInteger[] numbers) {
      if (numbers.length == 0)
          throw new ArithmeticException("There is nothing to multiply!");
      if (numbers.length == 1)
          return numbers[0];
      if (numbers.length == 2)
          return numbers[0].multiply(numbers[1]);
  
      BigInteger[] part1 = new BigInteger[numbers.length / 2];
      BigInteger[] part2 = new BigInteger[numbers.length - numbers.length / 2];
      System.arraycopy(numbers, 0, part1, 0, numbers.length / 2);
      System.arraycopy(numbers, numbers.length / 2, part2, 0, numbers.length - numbers.length / 2);
  
      return product(part1).multiply(product(part2));
  }
  </code></pre>
  
  <ul>
  <li>Note that BigInteger uses the karatsuba algorithm for multiplication.</li>
  <li>I know that there are lots of questions about calculating factorials. But mine is about calculating the product of BigIntegers for which there is not much resource. (I've seen someone say "Use Divide and Conquer method", but I don't remember where, and I haven't seen any implementation around.</li>
  </ul>