AtCoder Regular Contest 161
B
Exactly Three Bits
AtCoder
⌀ 563
原题
← AC →
翻译中…

Problem Statement

翻译中…

For a positive integer $X$, let $f(X)$ be the number of $1$s that appear when $X$ is represented in binary notation. For example, $6 = 110_{(2)}, \ 11 = 1011_{(2)}, \ 16 = 10000_{(2)}$, so $f(6) = 2, \ f(11) = 3, \ f(16) = 1$.

翻译中…

You are given a positive integer $N$. Determine whether there is a positive integer $X$ less than or equal to $N$ such that $f(X) = 3$, and if so, find the maximum such $X$.

翻译中…

There are $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 10^5$
  • $1 \leq N \leq 10^{18}$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format, where $N_i$ represents the value of $N$ in the $i$-th test case:

翻译中…

T
N_1
N_2
\vdots
N_T

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain the maximum positive integer $X$ less than or equal to $N_i$ such that $f(X) = 3$. If there is no such positive integer $X$, print -1.

翻译中…

样例

Input #1
4
16
161
4
1000000000000000000
Output #1
14
161
-1
936748722493063168
- For the first test case, $f(14) = 3, \ f(15) = 4, \ f(16) = 1$, so the maximum positive integer $X$ satisfying $X \leq 16$ and $f(X) = 3$ is $14$. - For the second test case, $f(161) = 3$, so the maximum positive integer $X$ satisfying $X \leq 161$ and $f(X) = 3$ is $161$. - For the third test case, $f(1) = 1, \ f(2) = 1, \ f(3) = 2, \ f(4) = 1$, so there is no positive integer $X$ satisfying $X \leq 4$ and $f(X) = 3$. - As seen in the fourth test case, the input and output values may not fit in a 32-bit integer type.
题目信息
题号
arc161_b
时间限制
2 s
内存限制
1024 MB

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