One More Problem About DFT

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

Let pp be a prime number and a=(a_0,a_1,,a_n1)a=(a\_0, a\_1, \ldots, a\_{n-1}) be an array of nn integers, where p=Kn+1p=Kn+1 for some positive integer KK. We say that the array a^=(a^_0,a^_1,,a^_n1)\hat{a}=(\hat{a}\_0, \hat{a}\_1, \ldots, \hat{a}\_{n-1}) is the Discrete Fourier Transform of the array aa if for every k=0,1,,n1k=0, 1, \ldots, n-1 the following holds:

a^_k=(_j=0n1a_jwjk)modp\hat{a}\_k = \left( \sum\_{j=0}^{n-1} a\_j w^{jk} \right) \bmod p

and we simply write a^=DFT(a)\hat{a} = \mathrm{DFT}(a). Here ww denotes a primitive nn-th root of unity modulo pp, that is, we have wn1(modp)w^n \equiv 1 \pmod p and, for every ii such that 0<i<n0 < i < n, wi≢1(modp)w^i \not \equiv 1 \pmod p.

Note that there can be multiple choices for ww, so the DFT\mathrm{DFT} won't be unique. Let us clarify how to uniquely find it for this problem. Let gg be a generator modulo pp, that is, for every xx such that 0<x<p0 < x < p, there exists a positive integer rr such that 0r<p10 \leq r < p-1 and x=grmodpx = g^r \bmod p. You can find the smallest positive value for gg that works and choose w=gKmodpw = g^K \bmod p.

Now we define \mathrm{DFT}^{(m)}(a) = \underbrace{\mathrm{DFT}(\mathrm{DFT}( \ldots \mathrm{DFT}(a) \ldots ))}\_{\text{m times}}, so your task is just to find DFT(m)(a)\mathrm{DFT}^{(m)}(a).

입력

The first line contains three space-separated integers: nn (2n31052 \leq n \leq 3 \cdot 10^5), pp (5p109+75 \leq p \leq 10^9+7), and mm (0m10180 \leq m \leq 10^{18}), the parameters of the problem described above. It is guaranteed that pp is prime and that nn divides p1p-1 evenly.

The second line contains nn space-separated integers a_0,a_1,,a_n1a\_0, a\_1, \ldots, a\_{n-1} (0a_i<p0 \leq a\_i < p), the array aa.

출력

Output nn space-separated integers a_0,a_1,,a_n1a'\_0, a'\_1, \ldots, a'\_{n-1}, the resulting array after doing the operation stated in the problem.

힌트

In the sample test case, the smallest possible generator for p=61p=61 is g=2g=2. We have that K=6116=10K = \frac{61 - 1}{6} = 10, so we choose w=210mod61=48w = 2^{10} \bmod 61 = 48 to be the primitive 66-th root of unity modulo 6161. The first iterations of the DFT\mathrm{DFT} are as follows:

  • DFT(0)(a)=(24,17,39,52,25,7)\mathrm{DFT}^{(0)}(a) = (24, 17, 39, 52, 25, 7)
  • DFT(1)(a)=(42,55,25,12,39,32)\mathrm{DFT}^{(1)}(a) = (42, 55, 25, 12, 39, 32)
  • DFT(2)(a)=(22,42,28,7,51,41)\mathrm{DFT}^{(2)}(a) = (22, 42, 28, 7, 51, 41)
  • DFT(3)(a)=(8,9,51,11,28,25)\mathrm{DFT}^{(3)}(a) = (8, 9, 51, 11, 28, 25)
  • DFT(4)(a)=(10,2,1,42,46,8)\mathrm{DFT}^{(4)}(a) = (10, 2, 1, 42, 46, 8)