欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1041B.Buying a TV Set
Buying a TV Set
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than and screen height not greater than . Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is , and the height of the screen is , then the following condition should be met: .
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers and there is a TV set with screen width and height in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers and , beforehand, such that , and .
In other words, Monocarp wants to determine the number of TV sets having aspect ratio , screen width not exceeding , and screen height not exceeding . Two TV sets are considered different if they have different screen width or different screen height.
Input
The first line contains four integers , , , () — the constraints on the screen width and height, and on the aspect ratio.
Output
Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
Note
In the first example, there are possible variants: , , .
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: .
Samples
17 15 5 3
3
14 16 7 22
0
4 2 6 4
1
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
1000000063
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |