eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

The Teacher`s Side of Math

The Teacher`s Side of Math

\includegraphics{https://static.e-olymp.com/content/a5/a5cdb5f9c0722cf818810c80d9fe9bb36b9da29f.jpg} One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial equation. It is, given a polynomial, say \textbf{X^2 − 4X + 1}, to find its roots (\textbf{2 ±} ). \includegraphics{https://static.e-olymp.com/content/b9/b9ac3a0fe5ea8905bfea1d86abd536bd54a08f90.jpg} If the students’ task is to find the roots of a given polynomial, the teacher’s task is then to find a polynomial that has a given root. Ms. Galsone is an enthusiastic mathematics teacher who is bored with finding solutions of quadratic equations that are as simple as \textbf{a + b}. She wanted to make higher-degree equations whose solutions are a little more complicated. As usual in problems in mathematics classes, she wants to maintain all coefficients to be integers and keep the degree of the polynomial as small as possible (provided it has the specified root). Please help her by writing a program that carries out the task of the teacher’s side. You are given a number t of the form: \includegraphics{https://static.e-olymp.com/content/4e/4ef0e5c6b55319fee9965fbf2353a64993eb9b2f.jpg} \includegraphics{https://static.e-olymp.com/content/1c/1c94ddab81da67e0deb8fef7b4c06c4a81ff6a98.jpg} \textbf{t =} + where \textbf{a} and \textbf{b} are distinct prime numbers, and \textbf{m} and \textbf{n} are integers greater than \textbf{1}. In this problem, you are asked to find t’s \textit{minimal polynomial on integers}, which is the polynomial \textbf{F(X) = a_dX^d + a_\{d−1\}X^\{d−1\} + · · · + a_1X + a_0} satisfying the following conditions. \begin{enumerate} \item Coefficients \textbf{a_0}, ..., \textbf{a_d} are integers and \textbf{a_d} > \textbf{0}. \item \textbf{F(t) = 0}. \item The degree \textbf{d} is minimum among polynomials satisfying the above two conditions. \item \textbf{F(X)} is primitive. That is, coefficients \textbf{a_0}, ..., \textbf{a_d} have no common divisors greater than one. \end{enumerate} \includegraphics{https://static.e-olymp.com/content/a5/a5cdb5f9c0722cf818810c80d9fe9bb36b9da29f.jpg} \includegraphics{https://static.e-olymp.com/content/f1/f19dae92f029c0e28dfe960261a1109b70591633.jpg} \includegraphics{https://static.e-olymp.com/content/a5/a5cdb5f9c0722cf818810c80d9fe9bb36b9da29f.jpg} \includegraphics{https://static.e-olymp.com/content/f1/f19dae92f029c0e28dfe960261a1109b70591633.jpg} For example, the minimal polynomial of \textbf{+} on integers is \textbf{F(X) = X^4−10X^2+1}. Verifying \textbf{F(t) = 0} is as simple as the following (\textbf{α} = , \textbf{β} = ). \textbf{F(t) = (α + β)^4 − 10(α + β)^2 + 1} \textbf{= (α^4 + 4α^3β + 6α^2β^2 + 4αβ^3 + β^4) − 10(α^2 + 2αβ + β^2) + 1} \textbf{= 9 + 12αβ + 36 + 8αβ + 4 − 10(3 + 2αβ + 2) + 1} \textbf{= (9 + 36 + 4 − 50 + 1) + (12 + 8 − 20)αβ = 0} Verifying that the degree of \textbf{F(t)} is in fact minimum is a bit more difficult. Fortunately, under the condition given in this problem, which is that \textbf{a} and \textbf{b} are distinct prime numbers and \textbf{m} and \textbf{n} greater than one, the degree of the minimal polynomial is always \textbf{mn}. Moreover, it is always \textit{monic}. That is, the coefficient of its highest-order term (\textbf{a_d}) is one. \InputFile The input consists of multiple datasets, each in the following format. \textbf{a m b n} \includegraphics{https://static.e-olymp.com/content/a5/a5cdb5f9c0722cf818810c80d9fe9bb36b9da29f.jpg} \includegraphics{https://static.e-olymp.com/content/f1/f19dae92f029c0e28dfe960261a1109b70591633.jpg} This line represents \textbf{m} + \textbf{n}. The last dataset is followed by a single line consisting of four zeros. Numbers in a single line are separated by a single space. Every dataset satisfies the following conditions. \begin{enumerate} \item \textbf{m} \includegraphics{https://static.e-olymp.com/content/a5/a5cdb5f9c0722cf818810c80d9fe9bb36b9da29f.jpg} + \textbf{n} \includegraphics{https://static.e-olymp.com/content/f1/f19dae92f029c0e28dfe960261a1109b70591633.jpg} ≤ \textbf{4}. \item \textbf{mn} ≤ \textbf{20}. \item The coefficients of the answer \textbf{a_0}, ..., \textbf{a_d} are between \textbf{(−2^31 + 1)} and \textbf{(2^31 − 1)}, inclusive. \end{enumerate} \OutputFile For each dataset, output the coefficients of its minimal polynomial on integers \textbf{F(X) = a_dX^d + a_\{d−1\}X^\{d−1\} + ··· + a_1X + a_0}, in the following format. \textbf{a_d a_\{d−1\} ... a_1 a_0} Non-negative integers must be printed without a sign (\textbf{+} or \textbf{−}). Numbers in a single line must be separated by a single space and no other characters or extra spaces may appear in the output.
Ліміт часу 5 секунд
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3 2 2 2
3 2 2 3
2 2 3 4
31 4 2 3
3 2 2 7
0 0 0 0
Вихідні дані #1
1 0 -10 0 1
1 0 -9 -4 27 -36 -23
1 0 -8 0 18 0 -104 0 1
1 0 0 -8 -93 0 24 -2976 2883 -32 -3720 -23064 -29775
1 0 -21 0 189 0 -945 -4 2835 -252 -5103 -1260 5103 -756 -2183
Джерело ACM ICPC Japan Regional 2007