#Q214. 「一本通 6.4 例 4」曹冲养猪
「一本通 6.4 例 4」曹冲养猪
Description
Since Cao Chong successfully dealt with the elephant, Cao Cao began to think about getting his son involved in some business. He sent him to a pig farm in the Central Plains to raise pigs. However, Cao Chong was unhappy and thus worked carelessly. Once, Cao Cao wanted to know the number of sows, so Cao Chong decided to play a trick on him.
For example, suppose there are sows. If pig pens are built, sow is left without a home; if pig pens are built, there is still sow without a place; if pig pens are built, sows are left without a place. As Cao Cao's personal secretary, it is your duty to report the accurate number of pigs to him. What should you do?
Input Format
The first line contains an integer , indicating the number of times pig pens were built.
The next lines each contain two integers and , indicating that pig pens were built, and sows were left without a place. You may assume that and are coprime for any and .
Output Format
Output only a single positive integer, which is the minimum number of sows Cao Chong raised.
Sample 1
3
3 1
5 1
7 2
16
Data Range and Hints
For all data, .