luogu#P10586. 「ALFR Round 2」B 篮球比赛
「ALFR Round 2」B 篮球比赛
Background
![]()
Problem Description
Xiaoshan is going to play basketball matches. He has a polynomial function and numbers whose sum is .
His team has a probability of to get the first victory in the -th match, which means they lost all of the first matches.
Next, if Xiaoshan’s team wins the -th match, then for , they have probability to get the next victory in the -th match. This means that if , they lose from match to match (if , then all matches after that are losses and there will be no more victories).
Xiaoshan wants to know the expected number of wins of his team. Can you help him?
Note: During calculation, if you meet fractions (such as ), you should use the “fraction modulo” form. If you do not know what “fraction modulo” means, see P2613 Template: Modulo of Rational Numbers.
To make computation easier, the input will directly give after taking modulo .
Input Format
The first line contains three integers , with meanings as described above.
The second line contains integers. The -th integer is the value of modulo .
The third line contains integers. The -th integer is the value of modulo .
Note that is given before .
Output Format
Output one number in one line, the answer modulo .
4 3 3
598946612 898419918 499122177
998244308 79 998244317 5
319837492
Hint
Sample Explanation
In the first sample: ; . The expected number of wins is .
Constraints
| Subtask | Score | Limit |
|---|---|---|
| - |
For of the testdata, , , and it is guaranteed that is not divisible by .
Translated by ChatGPT 5