F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Kaguya

Time Limit: 2000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 260    Accepted Submission(s): 84


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
2 2 2 772001 2 2 1000000007
 

Sample Output
241251 187500002
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 13:01:12, Gzip enabled