Compute the product a * b² * c³ ... efficiently
I absolutely don't know if this is the optimal approach (although I think it is asymptotically optimal), but you can do it all in O(N)
multiplications. You group the arguments of a * b^2 * c^3
like this: c * (c*b) * (c*b*a)
. In pseudocode:
result = 1
accum = 1
for i in 0 .. arguments:
accum = accum * arg[n-i]
result = result * accum
I think it is asymptotically optimal, because you have to use N-1
multiplications just to multiply N
input arguments.