Plotting Polynomials
Time limit2sMemory limit256 MB
Compute the initial forward-difference constants that let the given loop evaluate a degree-n polynomial at consecutive integers.
- Level
Medium6 of 10
- Topics
- Math, Combinatorics
- Solved
- No attempts yet
Problem
A graphing calculator draws a function on screen with almost no work from the student. The processor in such a calculator is slow, so the drawing routine has to be economical. This problem asks you to implement a method that speeds up the plotting of a polynomial.
Given a polynomial of degree , you want to plot it at the integer points . Evaluating the polynomial directly at each point costs multiplications and additions.
Reusing earlier results cuts that cost. If and is already known, then , so every later value costs one addition.
In general, once the initialization is done, additions turn into . With the constants chosen correctly, the pseudocode below produces .
p(0) = C_0; t_1 = C_1; ... t_n = C_n;
for i from 1 to m-1 do
p(i) = p(i-1) + t_1;
t_1 = t_1 + t_2;
t_2 = t_2 + t_3;
:
:
t_(n-1) = t_(n-1) + t_n;
end
For you can take and .
Compute the constants that make the pseudocode give the correct value of for every .
Input
The input is a single line. The first integer is , with . It is followed by the integer coefficients . Every coefficient satisfies , and .
Output
Print on one line, separated by single spaces.