#P4599. [HEOI2012] 赵州桥
[HEOI2012] 赵州桥
Description
While fyg was still amazed, the old man (could it be the legendary Mr. Zhang who once crossed Zhaozhou Bridge?!) began to speak: Mortal, you are now in my world. If you want to leave, you must answer my question. fyg nodded, and the old man continued: You are going to clear a series of levels. I give you colors, and there are levels in total (even immortals know math—what pressure...). In each level, there is a bridge. In level , the bridge has length units, and each unit length has cells (that is, the bridge has cells). Now you need to compute: the number of ways to color this bridge so that adjacent cells have different colors, then multiply it by . For example, in level , if you have colors, blue and green, then the final number would be ; the number of coloring schemes is (as shown in the figure; rotations and reflections are counted as different), and then you also multiply by two 2s. After you come out, I will ask you for the sum of the numbers computed for all levels. If you answer correctly, I will let you go; otherwise, you will be trapped in an endless cycle.

fyg thought the problem was too trivial and did not want to compute it at all... So he immediately opened his computer, logged into QQ, and found you, who enjoy calculations, asking you to directly compute the final answer and help him return to Zhaozhou Bridge.
These two numbers can both be very large, and fyg does not want to make it hard for you, so you only need to tell him the remainder when divided by .
Input Format
A single line containing three positive integers , , and , separated by spaces. The meanings of , , and are as described in the problem statement.
Output Format
One line, the remainder of the sum of the values modulo .
2 5 50
30
Hint
Sample Explanation
There are levels in total.
- In the first level, the bridge length is , there are cells in total, the number of coloring schemes is , then multiply by , and the number computed for the first level is .
- In the second level, the bridge length is , there are cells in total, the number of coloring schemes is , then multiply by , and the number computed for the second level is .
The sum of the two numbers leaves a remainder when divided by , so the output is .
Constraints
- For 25% of the testdata, , , .
- For 40% of the testdata, , , .
- For 15% of the testdata, , , .
- For the final 20% of the testdata, , , .
HEOI 2012 Day2 Task1.
Translated by ChatGPT 5
京公网安备 11011102002149号