UVa 10268: 498-bis | MathBlog
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1209
In 498 you had to evaluate the values of polynomial.
In this problem you should evaluate its derivative. Remember that derivative is defined as All the input and output data will fit into integer, i.e. its absolute value will be less than 2
Input
Your program should accept an even number of lines of text. Each pair of lines will represent one
problem. The first line will contain one integer - a value for x. The second line will contain a list of
integers a0, a1, ..., an−1, an, which represent a set of polynomial coefficients.
Input is terminated by <EOF>.
Output
For each pair of lines, your program should evaluate the derivative of polynomial for the given value x and output it in a single line.
Sample Input
7
1 -1
2
1 1 1
Sample Output
1
5
Don't worry if you don't know how to compute derivatives, since the formula for computing the derivative of a polynomial is given in the problem statement. If we have the polynomial:
then its derivative is:
Differentiation (computing the derivative) and integration (nearly the opposite of computing derivatives) are two fundamental operations in calculus. If you don’t know how to differentiate or integrate, I suggest you take a look at the calculus playlist at Khan Academy. It might come in handy in later Project Euler problems, for example when we need to maximize a function.
Read full article from UVa 10268: 498-bis | MathBlog
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1209
In 498 you had to evaluate the values of polynomial.
In this problem you should evaluate its derivative. Remember that derivative is defined as All the input and output data will fit into integer, i.e. its absolute value will be less than 2
Input
Your program should accept an even number of lines of text. Each pair of lines will represent one
problem. The first line will contain one integer - a value for x. The second line will contain a list of
integers a0, a1, ..., an−1, an, which represent a set of polynomial coefficients.
Input is terminated by <EOF>.
Output
For each pair of lines, your program should evaluate the derivative of polynomial for the given value x and output it in a single line.
Sample Input
7
1 -1
2
1 1 1
Sample Output
1
5
Don't worry if you don't know how to compute derivatives, since the formula for computing the derivative of a polynomial is given in the problem statement. If we have the polynomial:
public
Polynomial getDerivative() {
// create the derivative polynomial
// it has a degree one lower than the current polynomial
Polynomial der =
new
Polynomial(getDegree() -
1
);
// loop through all the coefficients of the current polynomial, except the last one
for
(
int
i = getDegree(); i >=
1
; i--) {
// the differentiated constant will be (the power of x, i) * (the old coefficient at x^i)
// and it will be at x^(i - 1)
der.set(i -
1
, i * get(i));
}
return
der;
}
Read full article from UVa 10268: 498-bis | MathBlog