#C9707. Valid Warehouse Locations
Valid Warehouse Locations
Valid Warehouse Locations
You are given a network of N junctions. A central warehouse is to be established at one of these junctions such that for any two junctions A and B the shortest distance (in terms of the number of junctions traveled) does not exceed a threshold D.
For the purpose of this problem, assume that the junctions are arranged in a circle. In such an arrangement, the maximum shortest path distance between any two junctions is \( \lfloor N/2 \rfloor \). Thus, a junction is a valid warehouse location if and only if \( D \geq \lfloor N/2 \rfloor \). If the condition holds for a test case, every junction is valid. Otherwise, no junction is suitable.
Your task is to determine, for each test case, the number of valid junctions where the central warehouse can be established.
inputFormat
The first line of input contains a single integer T representing the number of test cases. Each of the next T lines contains two space-separated integers: N (the number of junctions) and D (the maximum allowed distance).
\( 1 \leq T \leq 10^5 \), \( 1 \leq N \leq 10^9 \), and \( 0 \leq D \leq 10^9 \).
outputFormat
For each test case, output a single integer on a new line that indicates the number of valid junctions where the central warehouse can be established.
## sample3
5 2
6 2
7 3
5
0
7
</p>