#P5148. 大循环
大循环
Description
hke learned loop statements one day and found them amazing. Back home, he wrote the following code in C++:
void work()
{
ans=0;
for(a[1]=1;a[1]<=n;++a[1])
for(a[2]=1;a[2]<a[1];++a[2])
for(a[3]=1;a[3]<a[2];++a[3])
//......
for(a[k]=1;a[k]<a[k-1];++a[k])
ans+=f(q);
cout<<ans;
}
Here, is a given constant, and is a degree polynomial in , whose expression is:
$$f(x) = a _ m x ^ m + a _ {m - 1} x ^ {m - 1} + \cdots + a _ 1 x + a _ 0$$hke could not wait to run this program, but it was far too slow. So he came to you and wanted to know what the program outputs. The answer can be very large; you only need to output it modulo . Assume there is no overflow during the computation.
Input Format
The first line contains 4 positive integers .
The second line contains positive integers, namely .
Output Format
A single integer, representing the program’s result modulo .
10 3 3 2
1 3 3 1
3240
Hint
- For of the testdata, .
- For of the testdata, .
- For of the testdata, it is guaranteed that $n \le 500000, m \le 500000, 1 \le k \le n, q \le 10^{18}, 1 \le a_i \le 10000$.
Translated by ChatGPT 5
京公网安备 11011102002149号