codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1064B.md (2424B)


      1 Source: https://codeforces.com/problemset/problem/1064/B
      2 
      3 B. Equations of Mathematical Magic
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.
     22 
     23 Arkadi and Boris Strugatsky. Monday starts on Saturday
     24 
     25 Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $a - (a \oplus x) - x = 0$ for some given $a$, 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 $x$, 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.
     26 
     27 Input
     28 
     29 Each test contains several possible values of $a$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of these values.
     30 
     31 The following $t$ lines contain the values of parameter $a$, each value is an integer from $0$ to $2^{30} - 1$ inclusive.
     32 
     33 Output
     34 
     35 For each value of $a$ 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 $a$ appear in the input.
     36 
     37 One can show that the number of solutions is always finite.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 3  
     45 0  
     46 2  
     47 1073741823
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 1  
     54 2  
     55 1073741824
     56 ```
     57 
     58 Note
     59 
     60 Let's define the bitwise exclusive OR (XOR) operation. Given two integers $x$ and $y$, consider their binary representations (possibly with leading zeroes): $x_k \dots x_2 x_1 x_0$ and $y_k \dots y_2 y_1 y_0$. Here, $x_i$ is the $i$-th bit of the number $x$ and $y_i$ is the $i$-th bit of the number $y$. Let $r = x \oplus y$ be the result of the XOR operation of $x$ and $y$. Then $r$ is defined as $r_k \dots r_2 r_1 r_0$ where:
     61 
     62 $$ r_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i \end{aligned} \right. $$
     63 
     64 For the first value of the parameter, only $x = 0$ is a solution of the equation.
     65 
     66 For the second value of the parameter, solutions are $x = 0$ and $x = 2$.