Flat Earth
Time limit1sMemory limit1024 MB
The Earth grows by one layer of cells each second; a car moving 2 cells per second for K seconds must reach the edge, and we count valid starting cells for each N, K.
- Level
Medium7 of 10
- Topics
- Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
The Earth is flat. Haeseong firmly believes this, and he wants to travel to the edge of the Earth.
The Earth has a shape divided into cells as shown below, and it has a size .
When the size of the Earth is , it is a square shape with cells. Each time the size of the Earth grows by , one cell appears in an empty space adjacent to the edge of the Earth.
When the size of the Earth is , the edge of the Earth is the set of cells newly created when the size became .
When , every cell is the edge of the Earth.

In the picture above, the circled places are the edge of the Earth for , , and .
Haeseong can move cell per second. But since the size of the Earth also grows by each second, he realized that this way he can never reach the edge of the Earth, so he asked you, a wise person, for help.
Taking pity on him, you built a car that can move cells per second. Sadly, in a world where an infinite power battery has not yet been invented, the car can move only for seconds.
Given the size of the Earth when Haeseong starts and the time during which the car can move, count the number of starting cells from which he can reach the edge of the Earth.
Input
The input is given as follows.
- The first line gives the number of test cases . ()
- From the second line, lines each give one test case.
- is the current size of the Earth. ()
- You can use a car that moves cells per second for seconds. ()
Output
For each test case, in the order the test cases are given, output the number of cells from which the edge of the Earth can be reached, one per line, for a total of lines.