No.1253 Jan Ken Pon
Problem Statement
$N$ people played rock-paper-scissors using the hands Rock, Scissors, and Paper. For each of the $N$ participants, the probabilities of playing Rock, Scissors, and Paper are $\dfrac{A_G}{B_G},\dfrac{A_C}{B_C},\dfrac{A_P}{B_P}$, respectively. Also, the hands played by the $N$ people are independent. Let $R$ be the probability that the game ends in a draw. It can be shown that $R$ is a rational number; print this $R$ ${\rm mod} (10^9+7)$ in the way described in the notes below.
Solve $T$ test cases.
Notes
Printing the probability $R$ ${\rm mod} (10^9+7)$ means the following: when $R=\dfrac{P}{Q}$ ($P,Q$: integers, $Q$ is not a multiple of $10^9+7$ ), print the integer that is at least $0$ and less than $10^9+7$, $S$, satisfying $SQ \equiv P \pmod{10^9+7}$. Under the constraints of this problem, there exists at least 1 pair of integers $P,Q$ satisfying $R=\dfrac{P}{Q}$ ($P,Q$: integers, $Q$ is not a multiple of $10^9+7$ ).
Constraints
- $1 \leq T \leq 10^4$
- $2 \leq N \leq 10^{18}$
- $0 \leq A_G \leq B_G \leq 10^9$
- $0 \leq A_C \leq B_C \leq 10^9$
- $0 \leq A_P \leq B_P \leq 10^9$
- $B_G,B_C,B_P \neq 0$
- $\dfrac{A_G}{B_G}+\dfrac{A_C}{B_C}+\dfrac{A_P}{B_P}=1$
- All input values are integers.
Input
The input is given from standard input in the following format. The 1st line of the input is as follows.$T$The following $T$ lines then represent the $T$ test cases. Each of them is a line in the following format.
$N~A_G~B_G~A_C~B_C~A_P~B_P$
Sample
Sample 1
Input
5 2 1 3 1 3 1 3 2 1 2 1 3 1 6 3 1 3 1 3 1 3 4 1 5 2 5 4 10 5 1 1 0 1 0 1
Output
333333336 388888892 333333336 937600007 1
[About the 1st test case]
When 2 people play and the probability of each of the 3 hands is $\dfrac{1}{3}$, the probability of a draw is $\dfrac{1}{3}$.
Therefore, printing it ${\rm mod} (10^9+7)$ in the way described in the notes gives $333333336$.
[About the 4th test case]
The given fractions of the probabilities are not necessarily irreducible.提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Kazun
maspy