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            09/05/2016
MULFACR  CSECT
         USING MULFACR,13
SAVEAR   B     STM-SAVEAR(15)
         DC    17F'0'
STM      STM   14,12,12(13) prolog
         ST    13,4(15)     "
         ST    15,8(13)     "
         LR    13,15        " 
         LA    I,1          i=1
LOOPI    C     I,D          do i=1 to deg
         BH    ELOOPI       leave i
         LA    L,W+4          l=@p
         LA    J,1            j=1
LOOPJ    C     J,N            do j=1 to num
         BH    ELOOPJ         leave j
         LA    R,1              r=1
         LCR   S,I              s=-i
         LR    K,J              k=j
LOOPK    C     K,=F'2'          do k=j to 2 by s
         BL    ELOOPK           leave k
         MR    RR,K               r=r*k
         AR    K,S                k=k+s
         B     LOOPK            next k
ELOOPK   CVD   R,Y              pack r
         MVC   X,=XL12'402020202020202020202120' ed mask
         ED    X,Y+2            edit r 
         MVC   0(8,L),X+4       output r
         LA    L,8(L)           l=l+8
         LA    J,1(J)           j=j+1
         B     LOOPJ          next j
ELOOPJ   WTO   MF=(E,W)
         LA    I,1(I)         i=i+1
         B     LOOPI        next i
ELOOPI   L     13,4(0,13)   epilog
         LM    14,12,12(13) "
         XR    15,15        "
         BR    14           "
N        DC    F'10'        number
D        DC    F'5'         degree
W        DC    0F,H'84',H'0',CL80' ' length,zero,text
X        DS    CL12         temp
Y        DS    D            packed PL8
I        EQU   6
J        EQU   7
K        EQU   8
S        EQU   9
RR       EQU   10           even reg of R for MR opcode
R        EQU   11
L        EQU   12
         END   MULFACR