spoj#PWSUM. Power Sums
Power Sums
Everyone knows that we can express sums this form as polynomials of degree k+1. Most people find it hard to derive actual formulas for such sums, so we'd like to have a program that does that for us! You are given a nonnegative integer K, and you're asked to compute the coefficient representation of the polynomial which defines the sum shown above. However, we'd like to simplify your computation so you only have to output the formula modulo 10007. ( A formula which correctly computes the remainder of the sum when divided by 10007, for any natural x ).
Input
The first and only line of input contains a nonnegative integer k ( 0 <= k <= 300 ): the power we use in our sum.
Output
The first and only line of output should contain the canonic coefficient representation of the formula. To elaborate, this should be the form of your output:
ak+1xk+1 + akxk + ak-1xk-1 ... a0x0
ai here represents the coefficient that stands by the i-th power of x. As we only wish to find the formula modulo 10007, all the coefficients should be from interval [0, 10006] of integers. See the sample input and output for further clarification.
Example
Input:
1</p>Output:
5004x^2 + 5004x^1 + 0x^0
Input:
3
Output:
2502x^4 + 5004x^3 + 2502x^2 + 0x^1 + 0x^0