P28969 [洛谷] [BJOI2019] Light
提高+
题目描述

Problem 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 remaining light will be absorbed by the glass.

For any $x$, $x \times a_i\%$ units of light will pass through it, and $x \times b_i\%$ will be reflected back.

Now, $n$ layers of glass are stacked together, and $1$ unit of light hits the first layer of glass. How many units of light will pass through all $n$ layers of glass?

Input Format

The first line contains a positive integer $n$, representing the number of glass layers.

The next $n$ lines each contain two non-negative integers $a_i, b_i$, representing the transmittance and reflectance of the $i$-th layer of glass.

Output Format

Output a single integer, representing the amount of light that passes through all the glass layers modulo $10^9 + 7$.

It can be proven that the answer is always a rational number. Let the answer be $a/b$ (where $a$ and $b$ are coprime positive integers), and your output be $x$. You need to ensure that $a \equiv bx \ (\text{mod } 10^9 + 7)$.

Sample Input and Output

Sample Input #1

2
50 20
80 5

Sample Output #1

858585865

Sample Input #2

3
1 2
3 4
5 6

Sample Output #2

843334849

Notes

Sample 1 Explanation:

As shown in the figure, the light enters from the top left corner, with $0.5$ units of light passing through the first layer of glass and $0.2$ units being reflected back. This $0.5$ unit of light has $0.4$ units passing through the second layer of glass and $0.025$ units being reflected back. This $0.025$ unit of light has $0.0125$ units passing through the first layer of glass and $0.005$ units being reflected back. This $0.005$ unit of light has $0.004$ units passing through the second layer of glass... Thus, a total of $0.40404... = 40/99$ units of light pass through the two layers of glass. Under modulo $10^9+7$, this equals $858585865$.

Data Range:

For $5\%$ of the data, $n=1$;
For $20\%$ of the data, $n \le 2$;
For $30\%$ of the data, $n \le 3$;
For $50\%$ of the data, $n \le 100$;
For $70\%$ of the data, $n \le 3000$;
For $100\%$ of the data, $n \le 5 \times 10^5$, $1 \le a_i \le 100$, $0 \le b_i \le 99$, $1 \le a_i + b_i \le 100$.

Each pair of $a_i$ and $b_i$ is randomly generated within the above constraints.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 50 20 80 5
样例输出
858585865