Delivery Driver Minseo
Time limit1sMemory limit1024 MB
Minseo visits points 0, -1, 1, -2, 2, -4, 4, ... in order; for each query x, report the first time she arrives at x.
- Level
Medium6 of 10
- Topics
- Math, Implementation, Simulation, Binary search
- Solved
- No attempts yet
Problem
Minseo is a delivery driver. She greeted Monday in high spirits, but she could not help being startled. As the COVID-19 pandemic spread remote activities, the volume of deliveries surged. The deliveries assigned to Minseo numbered nearly infinity, and at this rate she would not escape death from overwork. For her health, Minseo decided to work hard only through today and, starting tomorrow, to become a professor instead of a delivery driver.
The neighborhood where Minseo lives can be represented as a number line, and Minseo is preparing to deliver from the origin of the number line, that is, from coordinate 0. Each delivery is numbered in order starting from 0, and the destination of a delivery can be represented as a coordinate on the number line. The destination of delivery is as follows.
Here is the floor function, meaning the largest integer not greater than . For example, the destination of delivery 3 can be computed as follows.
Minseo starts from the origin of the number line and delivers starting from delivery 0 in order. To deliver a package, she must move from her current position to the destination of the package. Minseo can move from her current coordinate to an adjacent coordinate, that is, to a coordinate differing by 1 from her current coordinate, and this takes 1 second. Minseo also always moves along a shortest path.
Minseo delivers packages all day long without rest. It occurs to her to wonder when she first reaches a particular coordinate on the number line.
Given a coordinate , write a program to find the time at which she first reaches that coordinate.
Input
The first line gives the number of test cases .
The following lines each give an integer coordinate , one per line.
Output
For each test case, output the answer on its own line.
Constraints
Hint
The volume of input and output is large, so using fast input and output is recommended.
Note that the answer can exceed the range representable by a 32-bit integer type.