Primorial of a Number

Published by Werdna in

In mathematics, primorial, denoted by “#”, is a function from natural numbers to natural numbers similar to the factorial function, but rather than successively multiplying positive integers, the function only multiplies prime numbers.

Create a function that takes an integer $num and returns its primorial.

Examples

primorial(1) ➞ 2
// First prime number = 2

primorial(2) ➞ 6
// Product of first two prime numbers = 2*3 = 6

primorial(6) ➞ 30030

Notes

n >= 1.

Watch a quick demo on how Edabit works.