Evaluate the primorial of a number
J, 13 characters
*/p:i._1 p:1+
Examples:
*/p:i._1 p:1+7
210
*/p:i._1 p:1+12
2310
Python 2, 49 bytes
P=k=1
exec"P*=P**k%k<1or k;k+=1;"*input()
print P
Counts up k
from 1 to the input, updating the primorial P
by multiplying P
by k
whenever it's prime. Since P
contains all lower prime factors, a sufficiently high power of P
will contain k
as a factor if and only if k
is non-prime. The power P**k
suffices, and we check whether P**k%k<1
, multipling P
by 1 if so (doing nothing) and by k
otherwise.
Python, 72 characters
Quickly golfed, I imagine there are better python solutions.
n=t=1;exec"t*=(1,n)[all(n%i for i in range(2,n))];n+=1;"*input();print t
I used wikipedia to verify up to 71
Usage:
$ python primorial.py
100
2305567963945518424753102147331756070
$ python primorial.py
101
232862364358497360900063316880507363070