欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1839A.The Good Array
The Good Array
You are given two integers and .
An array of length , consisting of zeroes and ones is good if for all integers from to both of the following conditions are satisfied:
- at least of the first elements of are equal to ,
- at least of the last elements of are equal to .
Here, denotes the result of division of by , rounded up. For example, , and .
Find the minimum possible number of ones in a good array.
Input
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases.
The only line of each test case contains two integers , (, ) — the length of array and parameter from the statement.
Output
For each test case output one integer — the minimum possible number of ones in a good array.
It can be shown that under the given constraints at least one good array always exists.
Note
In the first test case, and :
- Array is good and the number of ones in it is .
- Arrays , and are not good since for the first condition from the statement is not satisfied.
- Array is not good since for the second condition from the statement is not satisfied.
- All other arrays of length contain at least ones.
Thus, the answer is .
In the second test case, and :
- Array is not good since for the second condition is not satisfied.
- Array is good and the number of ones in it is .
- It can be shown that there is no good array with less than ones, so the answer is .
In the third test case, and :
- Array is good and the number of ones in it is .
- It can be shown that there is no good array with less than ones, so the answer is .
In the fourth test case, and . The only good array is , so the answer is .
Samples
7
3 2
5 2
9 3
7 1
10 4
9 5
8 8
2
3
4
7
4
3
2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |