#P7440. Sum over Derangements with Cycle Polynomial

    ID: 20635 Type: Default 1000ms 256MiB

Sum over Derangements with Cycle Polynomial

Sum over Derangements with Cycle Polynomial

Given two integers n and k, and a polynomial F(x) of degree k-1 defined by its coefficients, you are to compute for each integer m (1 ≤ m ≤ n):

S(m)=πF(cyc(π))S(m)=\sum_{\pi} F(\mathrm{cyc}(\pi))

Here, the sum is taken over all derangements \(\pi\) of length m (i.e. permutations with no fixed point, namely \(\pi_i \neq i\) for all i), and \(\mathrm{cyc}(\pi)\) denotes the number of cycles in the disjoint cycle decomposition of \(\pi\). The polynomial is given by

F(x)=a0+a1x++ak1xk1.F(x)=a_0+a_1x+\cdots+a_{k-1}x^{k-1}.

Your task is to output S(m) for each m from 1 to n, one per line.

inputFormat

The first line contains two integers n and k.

The second line contains k integers: a0, a1, ..., ak-1, which are the coefficients of the polynomial F(x) in increasing order of degree.

outputFormat

Output n lines. The m-th line (1-indexed) should contain the value of S(m), the sum of F(\(\mathrm{cyc}(\pi)\)) over all derangements \(\pi\) of length m.

sample

3 1
1
0

1 2

</p>