#P7468. [NOI Online 2021 提高组] 愤怒的小 N
[NOI Online 2021 提高组] 愤怒的小 N
Problem Description
The extremely angry Little N played a game to vent his anger.
This game has a total of levels: Level , Level , Level , , Level . Some of these levels are normal levels, and the others are bonus levels.
The distribution of normal and bonus levels in this game is special. Let character represent a normal level, and character represent a bonus level. Then the string formed by Level , Level , Level , , Level in order is a prefix of an infinite string , and can be constructed as follows:
-
Initially, is the string containing a single character .
-
Replace every character in with , and every character in with to obtain a string , then append to the end of .
-
Repeat step 2 continuously. The resulting string is the final .
We can see that . Therefore, Level of this game is a normal level, Level is a bonus level, Level is a bonus level, Level is a normal level, and so on.
Passing Level gives points, where is a fixed polynomial of degree .
When Little N cleared the game in a fit of anger, he passed all bonus levels and ignored all normal levels, and then uninstalled the game. Now, thinking back, he wants to know the result of his total score before uninstalling the game modulo .
Input Format
The first line contains a positive integer , which is the number of levels in the game. For convenience, is given in binary.
The second line contains a positive integer , which is one plus the degree of the polynomial.
The third line contains non-negative integers , which are the coefficients of the polynomial terms.
Output Format
Output one line containing a non-negative integer, which is Little N's total score before uninstalling the game modulo .
1000
3
3 2 1
110
11111100101
4
2 0 2 1
143901603
1001011001101001
16
1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1
184740992
Hint
For all test points: , , , .
| Test Point ID | ||
|---|---|---|
Thanks to s_r_f for providing the testdata.
Translated by ChatGPT 5