Codeforces Round 1078 (Div. 2)
A
Lawn Mower
Codeforces
800
原题
←B →
翻译中…

The exit from the summer cottage is fenced with a fence consisting of $n$ boards, each $1$ meter wide. To the left and right of the exit are the fences of other plots. Some of the boards of the fence want to be removed for the construction of a bathhouse (possibly all or none), while there is an automatic lawn mower on the plot that is $w$ meters wide and must not leave the plot through a hole in the fence.

翻译中…

The lawn mower will be able to exit the plot if there are at least $w$ consecutive removed boards among the numbers of the removed boards. Determine the maximum number of boards that can be removed from the fence.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$ and $w$ ($1 \leq n \leq 10^{9}$, $1 \leq w \leq 10^{9}$) — the number of boards in the fence and the width of the lawnmower in meters, respectively.

翻译中…

Output

翻译中…

For each test case, output a single number — the maximum number of boards that can be removed from the fence.

翻译中…

Note

翻译中…

In the first test case, the fence consists of $9$ boards.

翻译中…

image

翻译中…

You can remove $6$ boards and leave only the boards numbered $2$, $5$, and $8$. Then the lawn mower will not be able to leave the boundaries of the territory.

翻译中…

image

翻译中…

In the second test case, you can remove $10$ boards, a possible arrangement is shown below.

翻译中…

image

翻译中…

样例

Input #1
5
9 3
13 4
15 14
20 1
1000 42
Output #1
6
10
14
0
977
InputCopy OutputCopy
题目信息
题号
2194A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。