#P17387. [PacNW 2025] Pair-Linked Mokepon

    ID: 17449 Type: RemoteJudge 2000ms 2048MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>动态规划 DP2025组合数学前缀和ICPC

[PacNW 2025] Pair-Linked Mokepon

题目描述

A game of Mokepon consists of nn stations. The player starts at station 11. For every ii from 22 through nn, there is one special item with identifier ii, and the player must possess that item to move from station i−1i-1 to station ii. A station may hold any number of items, and a player may carry any number of items. The objective is to reach station nn.

You and a friend link two games: game A has nAn_A stations and game B has nBn_B stations. Every item is identified by a pair (i,A)(i,\mathrm A) or (i,B)(i,\mathrm B), indicating its identifier and the game it unlocks. An item may be placed at any station in either game. To advance to station ii in a game, either player must already have collected the corresponding item for that game.

Count the distributions of all items among all stations for which both players can reach the final station of their respective games. Two distributions differ if the set of items at some station differs. Output the count modulo the prime pp.

输入格式

The only line contains three integers nAn_A, nBn_B, and pp (2≤nA,nB≤3⋅1032\le n_A,n_B\le3\cdot10^3, 108≤p≤109+710^8\le p\le10^9+7). The value pp is guaranteed to be prime.

输出格式

Output the number of winning item distributions modulo pp.

2 2 1000000007
8
15 20 998244353
937612

提示

In the first sample, there are two items, (2,A)(2,\mathrm A) and (2,B)(2,\mathrm B). Each can be placed at any of four station-game locations, so there are 42=164^2=16 distributions in total. Exactly eight of them allow both players to win.