题号:NC200217
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
牛牛和牛妹在竞争技术组组长,于是同事们进行了一次不记名投票活动。
牛牛有特别的能力,可以在投票过程中对投票结果比窥探

次, 第

次窥探牛牛能够知道当前他的票数和牛妹的票数之比是

,但是他没法窥探到确切的票数是多少。
在窥探完

次之后,牛牛想知道在满足所有窥探结果比的前提下,当前他和牛妹所得的票数之和最小为多少?
Alice and Bob are engaged in a competition for tech group leader, for which all colleagues are voting between them.
Given that Alice is able to see the voting results for N times. At the i-th time, she is to know the votes she has got against Bob's in a ratio of

,however, she cannot see the actual amount of votes each time.
After seeing N times, given that all the ratios she sees are correct, Alice wants to know the minimal amount of votes that sums up both hers and Bob's.
输入描述:
输入包括
行。
第一行为一个正整数)
接下来

行,每行两个正整数
)
,保证两个数互质。
input contains

lines.
The 1st line is a positive integer
)
Then

lines follow, each line containing two positive integers
)
It is ensured that
%20%3D%3D%201)
.
输出描述:
输出最小可能的票数之和,保证答案不会超过

。
Output the minimal amount of votes that sums up both Alice's and Bob's, it is ensured that the answer does not exceed

.
示例1
说明
票数变化可能是:(2, 3) -> (3, 3) -> (6, 4),
所以最终的最小的票数之和为10。
the change of amount of votes can be : (2,3) -> (3, 3) -> (6, 4),
so the answer is 10.
示例3
输入
复制
5
3 10
48 17
31 199
231 23
3 2