|
||||||||||
KaguyaTime Limit: 2000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 335 Accepted Submission(s): 104 Problem Description One day, the student council secretary Fujiwara Chika asked a question from Shinomiya Kaguya: there are n nodes on the left side of a bipartite graph and m nodes on the right side. The probability of 0.5 between any two nodes on different sides has a two-way edge. She wants to know what is the expected distance between a left node and a right node? (The distance between two nodes is the minimum number of edges that must pass. If the two nodes are not connected, their distance is regarded as 0.) It is well known that Shinomiya Kaguya is an IT rookie, and this is why Shinomiya Kaguya is stumped. Seeing that Fujiwara Chika is about to win, Shinomiya Kaguya, who is cute and arrogant, asks for help. Can you help Miss Kaguya to win? Input The input contains a $T(T \leq 30)$ to indicate the number of case, followed by T rows, three numbers per line representing $n(1 \leq n \leq 30), m(1 \leq m \leq 30), P(772,001\leq P \leq 1,000,000,007)$ indicating that there are n nodes on the left side, m nodes on the right side, and P is a **prime** number. Output The output has a total of T lines, and one answer per line indicates the desired distance between a pair of nodes(one left node and one right node). It can be shown that it can be represented as $\frac{A}{B}$ where A and B are coprime integers and B≠0(mod P). Print the value of $A*B^{-1}$(mod P). Sample Input
Sample Output
Source | ||||||||||
|