#P6296. 轮换式 加强版
轮换式 加强版
Background
The only differences between this problem and the original one are the modulus and the Constraints.
Problem Description
Xiao Ben found that for any letters, the rotational form they form can be expressed as a linear combination of basic rotational forms.
Unary basic rotational form: ;
Binary: , ;
Ternary: , , ;
Quaternary: , , , ;
......
Given the values of all basic rotational forms of numbers, find the sum of their -th powers. Output the answer modulo ().
Input Format
The first line contains two positive integers , with meanings as described in the statement.
The next line contains positive integers. The -th number is , representing the value of the -th basic rotational form of variables.
Output Format
Output one integer in one line, representing the answer.
2 2
9 18
45
9 233333
9 1 8 7 5 6 3 4 2
100006329
Hint
[Explanation for Sample 1]
We can write the equations and , and it is easy to compute .
[Constraints]
- For of the testdata, , ;
- For of the testdata, , ;
- For of the testdata, , , .
Translated by ChatGPT 5