#P5323. [BJOI2019] 光线
[BJOI2019] 光线
Description
When a beam of light hits a layer of glass, a certain proportion of the light will pass through the glass, a certain proportion will be reflected back, and the rest will be absorbed by the glass.
Suppose for any , units of light will pass through it, and will be reflected back. Now there are layers of glass stacked together. If unit of light hits the st layer of glass, how many units of light can pass through all layers of glass?
Input Format
The first line contains a positive integer , representing the number of glass layers.
The next lines each contain two non-negative integers , representing the transmittance and reflectance of the -th layer.
Output Format
Output one line containing one integer, representing the amount of light that passes through all the glass layers modulo .
It can be proven that the answer must be a rational number. Let the answer be (where and are coprime positive integers). If the value you output is , you need to ensure that .
2
50 20
80 5
858585865
3
1 2
3 4
5 6
843334849
Hint
Explanation for Sample 1:

As shown in the figure, the light ray enters from the upper-left corner. There are units of light passing through the st layer of glass, and units of light being reflected back. Of these units of light, units pass through the nd layer of glass, and units of light are reflected back. Of these units of light, units pass through the st layer of glass, and units of light are reflected back. Of these units of light, units pass through the nd layer of glass... Therefore, the total amount of light passing through the two layers of glass is units. Modulo , this equals .
Constraints:
For of the testdata, ;
For of the testdata, ;
For of the testdata, ;
For of the testdata, ;
For of the testdata, ;
For of the testdata, , , , .
In each group, and are generated randomly among integers that satisfy the above constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号