CF BUDDY
← Problems·

1064B · Equations of Mathematical Magic

1200 · math

Problem: Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: a(ax)x=0a - (a \oplus x) - x = 0 for some given aa, where \oplus stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some xx, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.

Input Format: Each test contains several possible values of aa and your task is to find the number of equation's solution for each of them. The first line contains an integer tt (1t10001 \le t \le 1000) — the number of these values.

The following tt lines contain the values of parameter aa, each value is an integer from 00 to 23012^{30} - 1 inclusive.

Output Format: For each value of aa print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of aa appear in the input.

One can show that the number of solutions is always finite.

Note: Let's define the bitwise exclusive OR (XOR) operation. Given two integers xx and yy, consider their binary representations (possibly with leading zeroes): xkx2x1x0x_k \dots x_2 x_1 x_0 and yky2y1y0y_k \dots y_2 y_1 y_0. Here, xix_i is the ii-th bit of the number xx and yiy_i is the ii-th bit of the number yy. Let r=xyr = x \oplus y be the result of the XOR operation of xx and yy. Then rr is defined as rkr2r1r0r_k \dots r_2 r_1 r_0 where:

ri={1, if xiyi0, if xi=yir_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i \end{aligned} \right.

For the first value of the parameter, only x=0x = 0 is a solution of the equation.

For the second value of the parameter, solutions are x=0x = 0 and x=2x = 2.

Sample Cases

Case 1

Input

3
0
2
1073741823

Output

1
2
1073741824

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback