The factorial of a number, written as 



n
!


{\displaystyle n!}

, is defined as 



n
!
=
n
(
n
−
1
)
(
n
−
2
)
.
.
.
(
2
)
(
1
)


{\displaystyle n!=n(n-1)(n-2)...(2)(1)}

.

Multifactorials generalize factorials as follows:

 



n
!
=
n
(
n
−
1
)
(
n
−
2
)
.
.
.
(
2
)
(
1
)


{\displaystyle n!=n(n-1)(n-2)...(2)(1)}


 



n
!
!
=
n
(
n
−
2
)
(
n
−
4
)
.
.
.


{\displaystyle n!!=n(n-2)(n-4)...}


 



n
!
!
!
=
n
(
n
−
3
)
(
n
−
6
)
.
.
.


{\displaystyle n!!!=n(n-3)(n-6)...}


 



n
!
!
!
!
=
n
(
n
−
4
)
(
n
−
8
)
.
.
.


{\displaystyle n!!!!=n(n-4)(n-8)...}


 



n
!
!
!
!
!
=
n
(
n
−
5
)
(
n
−
10
)
.
.
.


{\displaystyle n!!!!!=n(n-5)(n-10)...}


In all cases, the terms in the products are positive integers.

If we define the degree of the multifactorial as the difference in successive terms that are multiplied together for a multifactorial (the number of exclamation marks), then the task is twofold:

 Write a function that given n and the degree, calculates the multifactorial.
 Use the function to generate and display here a table of the first ten members (1 to 10) of the first five degrees of multifactorial.

Note: The wikipedia entry on multifactorials gives a different formula. This task uses the Wolfram mathworld definition.

MultiFactorial := function(n, k)
    local r;
    r := 1;
    while n > 1 do
        r := r*n;
        n := n - k;
    od;
    return r;
end;
 
PrintArray(List([1 .. 10], n -> List([1 .. 5], k -> MultiFactorial(n, k))));
[ [        1,        1,        1,        1,        1 ],
  [        2,        2,        2,        2,        2 ],
  [        6,        3,        3,        3,        3 ],
  [       24,        8,        4,        4,        4 ],
  [      120,       15,       10,        5,        5 ],
  [      720,       48,       18,       12,        6 ],
  [     5040,      105,       28,       21,       14 ],
  [    40320,      384,       80,       32,       24 ],
  [   362880,      945,      162,       45,       36 ],
  [  3628800,     3840,      280,      120,       50 ] ]