NR1 - Kapti and Balu
Kapti and Balu are friends. Kapti is very good in math and is always saying that no one can challenge him in math. One day Balu decided to check Kapti that he is really good in math or he is just making fool.
Balu gave Kapti a polynomial of degree “n” and ask Kapti to find constant term “L” if the polynomial was first expressed in Factorial Notation and then subjected to Forward Difference operator for “k” imes.
If
f(x) = a1xn + a2xn-1 + ... + anx + l
then its factorial notation will be:
fFN(x) = A1[x]n + A2[x]n-1 + ... + An[x] + L
Where
[x]n = x(x-1)(x-2) ... (x-n+1)
And forward difference operator Δ is just simple differentiation of fFN(x).
For example
f(x) = 2x3 - 3x2 + 3x - 10 fFN(x) = 2[x]3 + 3[x]2 + 2[x] - 10 ΔfFN(x) = 6[x]2 + 6[x] + 2 here constant term L = 2 and k = 1;
Help kapti in proving himself that he is good in math.
Input
Input start with integer T (< 30) denoting the number of test cases.
Each test case will contains two lines,
First line contains n (<= 25) and k (<= n)
Second line contains n+1 integers a1 a2 a3 ... an l, -50 <= ai <= 50
Output
For each test case print one line containing L.
Example
Input: 1 3 2 2 -3 3 -10 Output: 6
hide comments
RIVU DAS:
2014-06-04 09:15:27
Nice one!! Learned a lot! |
|
Bhavik:
2014-06-04 09:15:27
@Nishant Raj: I must thank you for making this problem:) I learned many new mathematical concepts to solve this problem |
|
Jumpy:
2014-06-04 09:15:27
finally after lots of WA got TLE the question would have been more interesting if there was modulo concept... |
|
રચિત (Rachit):
2014-06-04 09:15:27
A suggestion: To prevent overflows in C/CPP, can you please modify your problem statement to print the answer modulus some prime. |
|
NISHANT RAJ:
2014-06-04 09:15:27
@anurag : in c++ during calculation overflow may occure.:
|
|
anurag garg:
2014-06-04 09:15:27
@nishant raj
|
|
Francky:
2014-06-04 09:15:27
You should not set some time limit near zero, there's a little time for start interpreter. Here, you could increase time limit and constraints, on T or on maxN.
|
|
Anant Kumar:
2014-06-04 09:15:27
Nice question! Knowledge of factorial notation of polynomial is prerequisite.
|
|
Bhavik:
2014-06-04 09:15:27
@Nishant: how did coefficient of x changes to 2 from 3 in fFN(x)??
|
Added by: | NISHANT RAJ |
Date: | 2014-03-08 |
Time limit: | 0.100s-0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | own |