This question already has an answer here:

For the purposes of this question, the prime factorial of a number n is the result of multiplying all prime numbers smaller than n, and then multiplying the result by n.

Your Task:

Write a program or function to find the prime factorial of a number, as outlined above.


An integer n where n is greater than one, and the prime factorial of n is smaller than the largest integer your language can support. However, remember this standard loophole. Reasonable integer limits only.


The prime factorial of the input.

Test Cases:

4  -> 24
7  -> 210
32 -> 641795684160


This is , lowest score in bytes wins!


marked as duplicate by xnor code-golf Oct 1 '17 at 21:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ No way we haven't had this challenge before... \$\endgroup\$ – xnor Oct 1 '17 at 21:01
  • \$\begingroup\$ @xnor This? \$\endgroup\$ – H.PWiz Oct 1 '17 at 21:01
  • \$\begingroup\$ I didn't think of searching for "primorial" when I was dupe-checking. Sandbox didn't catch it either. \$\endgroup\$ – Gryphon Oct 1 '17 at 21:04
  • \$\begingroup\$ @Gryphon Yeah, it's strange that "prime factorial" doesn't appear on that challenge. I edited it to make it a bit more searchable. \$\endgroup\$ – xnor Oct 1 '17 at 21:06
  • \$\begingroup\$ Thanks. I thought it was weird we hadn't already had something like this, but I couldn't find anything, so I posted in the sandbox, which also didn't find anything. \$\endgroup\$ – Gryphon Oct 1 '17 at 21:08

Jelly, 5 bytes


Try it online!


’ÆRP×   Full program.

’       Decrement.
 ÆR     Inclusive prime range.
   P    Product.
    ×   Multiply by the input.

The non-built-in would be 7 bytes: ’ÆPÐfP×


Pyth, 10 bytes


I'm pretty sure this can be golfed some more...

*Q*FfP_TSt     Full program, takes input from stdin and outputs to stdout
*Q             Implicitly output $input multiplied by 
  *F           The product of
        St(Q)  All numbers less than $input (Q is added automtaically by Pyth)
    fP_T       As long as they are prime
  • \$\begingroup\$ Pretty sure you can omit the Q \$\endgroup\$ – Leaky Nun Oct 1 '17 at 21:04
  • \$\begingroup\$ Can you replace St with U? \$\endgroup\$ – Leaky Nun Oct 1 '17 at 21:04
  • \$\begingroup\$ 8 bytes: **FfP_TU or *F+fP_TU \$\endgroup\$ – Mr. Xcoder Oct 1 '17 at 21:06

MATLAB/Octave, 23 bytes


Try it online!

  • \$\begingroup\$ Mobile bug.. >_> \$\endgroup\$ – Leaky Nun Oct 1 '17 at 21:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.