luogu#P3762. [TJOI2017] 龙舟
[TJOI2017] 龙舟
Background
Description
Jialidun University has a dragon boat club with teams, each consisting of paddlers. Dragon boat racing is a team sport, and while it depends on each individual’s ability, coordination is crucial. Therefore, the ability of a team is evaluated by the value $C=\frac{b_1 \times b_2 \times \cdots \times b_m}{a_1 \times a_2 \times \cdots \times a_m}$, where is the standard ability value for position , and is the ability value of the paddler in position in the team. After cancellation, we obtain with , i.e., and are coprime.
However, due to varying conditions at the venue, we consider that under pressure , the team’s final performance is . We define that under modulo , , where satisfies and . If no such exists, we say the team will underperform under pressure (that is, is the modular inverse of modulo ; if the inverse does not exist, the team underperforms). Given this season’s schedule, the coaching staff wants to know each team’s performance in the matches.
Output Format
Output lines. For the -th scheduled match, output the team’s on-site performance value . If the team underperforms (i.e., the inverse does not exist), output -1.
2 3 3
5 2 3
3 2 3
2 3 2
1 4
2 4
1 7
3
-1
4
Hint
For of the testdata, , .
For of the testdata, , , , .
Translated by ChatGPT 5