#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 mm colors, and there are nn levels in total (even immortals know math—what pressure...). In each level, there is a bridge. In level ii, the bridge has length ii units, and each unit length has 22 cells (that is, the bridge has 2i2i 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 (2×i)m(2 \times i)^m. For example, in level 11, if you have 22 colors, blue and green, then the final number would be 2×2×2=82 \times 2 \times 2 = 8; the number of coloring schemes is 22 (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 pp.

Input Format

A single line containing three positive integers nn, mm, and pp, separated by spaces. The meanings of nn, mm, and pp are as described in the problem statement.

Output Format

One line, the remainder of the sum of the values modulo pp.

2 5 50 
30

Hint

Sample Explanation

There are 22 levels in total.

  • In the first level, the bridge length is 11, there are 22 cells in total, the number of coloring schemes is 2020, then multiply by 252^5, and the number computed for the first level is 640640.
  • In the second level, the bridge length is 22, there are 44 cells in total, the number of coloring schemes is 260260, then multiply by 454^5, and the number computed for the second level is 266240266240.

The sum of the two numbers leaves a remainder 3030 when divided by 5050, so the output is 3030.

Constraints

  • For 25% of the testdata, n106n \leq 10^6, m200m \leq 200, p109p \leq 10^9.
  • For 40% of the testdata, n109n \leq 10^9, m120m \leq 120, p109p \leq 10^9.
  • For 15% of the testdata, n109n \leq 10^9, m200m \leq 200, p109p \leq 10^9.
  • For the final 20% of the testdata, n109n \leq 10^9, m3000m \leq 3000, p3000p \leq 3000.

HEOI 2012 Day2 Task1.

Translated by ChatGPT 5