Codeforces Round 926 (Div. 2)
B
Sasha and the Drawing
Codeforces
800
原题
← AC →
翻译中…

Even in kindergarten, Sasha liked a girl. Therefore, he wanted to give her a drawing and attract her attention.

翻译中…

As a drawing, he decided to draw a square grid of size $n \times n$, in which some cells are colored. But coloring the cells is difficult, so he wants to color as few cells as possible. But at the same time, he wants at least $k$ diagonals to have at least one colored cell. Note that the square grid of size $n \times n$ has a total of $4n - 2$ diagonals.

翻译中…

Help little Sasha to make the girl fall in love with him and tell him the minimum number of cells he needs to color.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$ and $k$ ($2 \leq n \leq 10^8$, $1 \leq k \leq 4n - 2$) — the size of the square grid and the minimum number of diagonals in which there should be at least one colored cell.

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum number of cells that need to be colored.

翻译中…

Note

翻译中…

In the pictures below, the colored cells are marked in black, and all diagonals are marked in purple.

翻译中…

In the first test case, you can color $2$ cells so that $4$ diagonals contain at least one colored cell:

翻译中…

image

翻译中…

In the third test case, you can color $6$ cells so that all $10$ diagonals contain at least one colored cell:

翻译中…

image

翻译中…

样例

Input #1
7
3 4
3 3
3 10
3 9
4 7
7 11
2 3
Output #1
2
2
6
5
4
6
2
InputCopy OutputCopy
题目信息
题号
1929B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
数学

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