#P8918. 『MdOI R5』Jump

    ID: 9099 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学洛谷原创O2优化位运算洛谷月赛

『MdOI R5』Jump

Problem Description

There is a person on a number line. Let their position be xx, and initially x=0x=0. In the ii-th second, they can choose to jump left or right by 2i12^{i-1} units, that is, increase or decrease xx by 2i12^{i-1}. Find the minimum number of seconds needed to reach nn, meaning that at the end of some second, x=nx=n. If it is impossible to ever reach nn, output 1-1.

In this problem, each test point contains multiple test cases.

Input Format

The first line contains an integer TT, the number of test cases.

The next TT lines each contain an integer, representing nn in one test case.

Output Format

Output TT lines. Each line contains one number, in order, representing the answer for each test case.

10
1
2
7
8
9
10
11
935
101
2023
1
-1
3
-1
4
-1
4
10
7
11

Hint

For 100%100\% of the data, 1T1031\le T\le 10^3, 1n1091\le n\le 10^9.

Subtask1(30%)\operatorname{Subtask} 1(30\%): n100n\le 100.

Subtask2(40%)\operatorname{Subtask} 2(40\%): n=2kn=2^k, where kk is a non-negative integer.

Subtask3(30%)\operatorname{Subtask} 3(30\%): No special constraints.

Sample Explanation 1

When n=1n=1, it is enough to jump to the right in the first second.

When n=2n=2, it can be proven that it is impossible to ever reach nn.

Translated by ChatGPT 5