A8523 | Space Voyage
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit $n$ planets. For planet $i$ $a_{i}$ is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and $b_{i}$ is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, $x$ presents in each. The Beaver will take to the ship exactly $a_{1}+...+a_{n}$ suitcases.
As the Beaver lands on the $i$ -th planet, he takes $a_{i}$ suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens — each of the $b_{i}$ citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly $c$ days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer $x$ so that the planned voyage will take exactly $c$ days?
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, $x$ presents in each. The Beaver will take to the ship exactly $a_{1}+...+a_{n}$ suitcases.
As the Beaver lands on the $i$ -th planet, he takes $a_{i}$ suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens — each of the $b_{i}$ citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly $c$ days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer $x$ so that the planned voyage will take exactly $c$ days?
输入格式
The first input line contains space-separated integers $n$ and $c$ — the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next $n$ lines contain pairs of space-separated integers $a_{i},b_{i}$ ( $1<=i<=n$ ) — the number of suitcases he can bring to the $i$ -th planet and the number of citizens of the $i$ -th planet, correspondingly.
The input limitations for getting 30 points are:
- $1<=n<=100$
- $1<=a_{i}<=100$
- $1<=b_{i}<=100$
- $1<=c<=100$
The input limitations for getting 100 points are:
- $1<=n<=10^{4}$
- $0<=a_{i}<=10^{9}$
- $1<=b_{i}<=10^{9}$
- $1<=c<=10^{9}$
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
The next $n$ lines contain pairs of space-separated integers $a_{i},b_{i}$ ( $1<=i<=n$ ) — the number of suitcases he can bring to the $i$ -th planet and the number of citizens of the $i$ -th planet, correspondingly.
The input limitations for getting 30 points are:
- $1<=n<=100$
- $1<=a_{i}<=100$
- $1<=b_{i}<=100$
- $1<=c<=100$
The input limitations for getting 100 points are:
- $1<=n<=10^{4}$
- $0<=a_{i}<=10^{9}$
- $1<=b_{i}<=10^{9}$
- $1<=c<=10^{9}$
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
输出格式
Print a single number $k$ — the number of ways to choose $x$ so as to travel for exactly $c$ days. If there are infinitely many possible values of $x$ , print -1.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
输入输出样例
输入 #1
2 5 1 5 2 4
输出 #1
1
In the first example there is only one suitable value $x=5$ . Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days — he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For $x=4$ or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For $x=6$ and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
For $x=4$ or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For $x=6$ and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted