#P5409. Computation of Unsigned Stirling Numbers of the First Kind
Computation of Unsigned Stirling Numbers of the First Kind
Computation of Unsigned Stirling Numbers of the First Kind
The unsigned Stirling numbers of the first kind, \(\begin{bmatrix} n\\ m \end{bmatrix}\), represent the number of ways to arrange \(n\) distinct elements into \(m\) circular permutations (cycles). Given two integers \(n\) and \(k\), compute \(\begin{bmatrix} i\\ k \end{bmatrix}\) modulo \(167772161\) (where \(167772161 = 2^{25}\times 5+1\), a prime number) for all integers \(i \in [0, n]\).
The recurrence relation is given by:
[ \begin{bmatrix} n \ k \end{bmatrix} = \begin{bmatrix} n-1 \ k-1 \end{bmatrix} + (n-1) \begin{bmatrix} n-1 \ k \end{bmatrix} ]
with the initial conditions \(\begin{bmatrix} 0 \\ 0 \end{bmatrix} = 1\) and \(\begin{bmatrix} n \\ k \end{bmatrix} = 0\) if \(n < k\) or \(k 0\), we have \(\begin{bmatrix} n \\ 0 \end{bmatrix} = 0\).
inputFormat
The input consists of two space-separated integers:
- \(n\): the maximum number of elements.
- \(k\): the fixed number of cycles.
\(n\) and \(k\) may be provided in one line.
outputFormat
Output \(n+1\) numbers separated by spaces. The \(i\)th number (where \(i\) ranges from \(0\) to \(n\)) is the value of \(\begin{bmatrix} i \\ k \end{bmatrix}\) modulo \(167772161\).
sample
5 3
0 0 0 1 6 35