The $k^{th}$ order multifactorial for $n \in \mathbb{N}$ is defined commonly as the follows: enter image description here

Which is equivalent to

enter image description here

I saw a succinct line of code on RosettaCode for generating the $k^{th}$ order multifactorial for $n \in \mathbb{N}$ as follows:

Multifactorial[n_, k_] := Abs[ Apply[ Times, Range[-n, -1, k]]]

Could someone explain me how the code works in a sort of step by step manner since I am unable to quite understand it.


1 Answer 1


You can start by understanding how Apply works. For example

Apply[f, {a, b, c}]


So, if you need product of these three numbers, you use

Apply[Times, {a, b, c}]

a b c

Now what remains is to find the right elements to multiply. For kth multifactorial of n it is {n,n-k,n-2k,...} which you can write as


Your code construct the series in reverse order and so it requires Abs in front. Therefore

Multifactorial[n_, k_] := Apply[Times, Range[n, 1, -k]]


  • $\begingroup$ Thanks that's a good explanation. $\endgroup$ Feb 27, 2021 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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