#P3711. Hamster's Summation Challenge

    ID: 16962 Type: Default 1000ms 256MiB

Hamster's Summation Challenge

Hamster's Summation Challenge

Given two integers n and x, and a sequence of n+1 integers a0, a1, ..., an, define

Sk(x)=\( \sum_{i=0}^{x} i^k \) ,

with the special definition that \(0^0=1\) (i.e. when i=0 and k=0, treat it as 1). You are to compute

\( \sum_{k=0}^{n} S_k(x) \times a_k \).

Note: It is guaranteed that the values of n and x are relatively small (at most 1000), so a simple iterative solution will suffice.

inputFormat

The input consists of two lines:

  • The first line contains two integers n and x, where n (0 ≤ n ≤ 1000) denotes the highest power index and x (0 ≤ x ≤ 1000) is the upper limit of summation.
  • The second line contains n+1 integers: a0, a1, ..., an.

outputFormat

Output a single integer representing the value of \( \sum_{k=0}^{n} S_k(x) \times a_k \).

sample

1 2
1 1
6