JavaScript (ES7), 64 bytes
a=>(g=d=>n%--d?g(d):d<2?n**a.shift()*(a+a?g(++n):1):g(++n))(n=2)
With BigInts, 65 bytes
A version that supports large integers. Expects a list of BigInts.
a=>(g=d=>n%--d?g(d):d<2?n**a.shift()*(a+a?g(++n):d):g(++n))(n=2n)
Commented
a => ( // a[] = input array
g = d => // g is a recursive function taking a divisor d
n % --d ? // decrement d; if it's not a divisor of n:
g(d) // do recursive calls until it is
: // else:
d < 2 ? // if d is less than 2 (n is prime):
n ** a.shift() // multiply the final result by n to the power
// of the next exponent extracted from a[]
* ( // and multiply by:
a + a ? // if a[] is not empty:
g(++n) // the result of a recursive call with n + 1
: // else:
1 // just 1
) //
: // else (n is composite):
g(++n) // return the result of a recursive call with n + 1
)(n = 2) // initial call to g with d = n = 2
Arnauld
- 205.5k
- 21
- 187
- 670