A young schoolboy would like to calculate the sum
for some fixed natural k and different natural n. He observed that calculating i
k for all i (1<=i<=n) and summing up results is a too slow way to do it, because the number of required arithmetical operations increases as n increases. Fortunately, there is another method which takes only a constant number of operations regardless of n. It is possible to show that the sum S
k(n) is equal to some polynomial of degree k+1 in the variable n with rational coefficients, i.e.,
We require that integer M be positive and as small as possible. Under this condition the entire set of such numbers (i.e. M, a
k+1, a
k, ... , a
1, a
0) will be unique for the given k. You have to write a program to find such set of coefficients to help the schoolboy make his calculations quicker.