in reply to how to multiply an array of number as fast as posible
For a totally off the wall suggestion, you could factor each of the multiplicands into a series of prime numbers, then increment the count of each prime number. At the end of the process, calculate the products of all of the powers.
So 30*22*45 would break down to (2*3*5) * (2*11) * (3*3*5), giving 2^2, 3^3, 5^2 and 11^1, or 4 * 9 * 25 * 11.
The advantage of this approach is that you're not doing multiplications over and over again, you're just factoring and saving counts of prime numbers. The only multiplication is done at the very end.
|
|---|