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

Rational Approximation

Rational Approximation

A polynomial \textbf{p(x)} of degree \textbf{n} can be used to approximate a function \textbf{f(x)} by setting the coecients of \textbf{p(x)} to match the first \textbf{n} coecients of the power series of \textbf{f(x)} (expanded about \textbf{x = 0}). For example, \includegraphics{https://static.e-olymp.com/content/da/da1b0445915a324360cc06cf067bf649f13bd0f9.jpg} Unfortunately, polynomials are "nice" and they do not work well when they are used to approximate functions that behave poorly (e.g. those with singularities). To overcome this problem, we can instead approximate functions by rational functions of the form \textbf{p(x)/q(x)}, where \textbf{p(x)} and \textbf{q(x)} are polynomials. You have been asked by Approximate Calculation Machinery to solve this problem, so they can incorporate your solution into their approximate calculation software. Given \textbf{m}, \textbf{n}, and the first \textbf{m+n} coecients of the power series of \textbf{f(x)}, we wish to compute two polynomials \textbf{p(x)} and \textbf{q(x)} of degrees at most \textbf{m-1} and \textbf{n-1}, respectively, such that the power series expansion of \textbf{q(x)·f(x)-p(x)} has \textbf{0} as its first \textbf{m+n-1} coecients, and \textbf{1} as its coecient corresponding to the \textbf{x^\{m+n-1\}} term. In other words, we want to find \textbf{p(x)} and \textbf{q(x)} such that \includegraphics{https://static.e-olymp.com/content/a6/a636dd28729908c8e0a13f271ac3840fe5b51cf2.jpg} where ... contains terms with powers of \textbf{x} higher than \textbf{m+n-1}. From this, \textbf{f(x)} can be approximated by \textbf{p(x)/q(x)}. \textbf{Background De nitions} A polynomial \textbf{p(x)} of degree \textbf{n} can be written as \textbf{p_0 + p_1x + p_2x^2 + ... + p_nx^n}, where \textbf{p_i}'s are integers in this problem. A power series expansion of \textbf{f(x)} about \textbf{0} can be written as \textbf{f_0 +f_1x+f_2x^2+...}, where \textbf{f_i}'s are integers in this problem. \InputFile The input will consist of multiple cases. Each case will be speci ed on one line, in the form \textbf{m n f_0 f_1 ... f_\{m+n-1\}} where \textbf{f_\{i \}}is the coecient of \textbf{x_i} in the power series expansion of \textbf{f}. You may assume that \textbf{1} ≤ m, \textbf{1} ≤ \textbf{n} ≤ \textbf{4}, \textbf{2} ≤ \textbf{m+n} ≤ \textbf{10}, and \textbf{f_\{i \}}are integers such that \textbf{|f_i|} ≤ \textbf{5}. The end of input will be indicated by a line containing \textbf{m = n = 0}, and no coecients for \textbf{f}. You may assume that there is a unique solution for the given input. \OutputFile For each test case, print two lines of output. Print the polynomial \textbf{p(x)} on the first line, and then \textbf{q(x)} on the second line. The polynomial \textbf{p(x)} should be printed as a list of pairs \textbf{(p_i, i)} arranged in ascending order in \textbf{i}, such that \textbf{p_i} is a non-zero coecient for the term \textbf{x_i}. Each non-zero coecient \textbf{p_i} should be printed as \textbf{a/b}, where \textbf{b} > \textbf{0} and \textbf{a/b} is the coecient expressed in lowest terms. In addition, if \textbf{b = 1} then print only \textbf{a} (and omit \textbf{b}). If \textbf{p(x) = 0}, print a line containing only \textbf{(0, 0)}. Separate the pairs in the list by one space. The polynomial \textbf{q(x)} should be printed in the same manner. Insert a blank line between cases.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
2 2 0 0 1 1
4 2 1 2 3 4 5 -2
1 1 2 3
1 4 -5 0 -2 1 -2
0 0
Выходные данные #1
(0,0)
(1,1)

(-4/33,0) (-1/11,1) (-2/33,2) (-1/33,3)
(-4/33,0) (5/33,1)

(2/3,0)
(1/3,0)

(25/6,0)
(-5/6,0) (1/3,2) (-1/6,3)
Источник ACM ICPC East Central Regional Contest 2000