Description

Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.
Arkadi and Boris Strugatsky. Monday starts on Saturday

Reading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: a−(a⊕x)−x=0

for some given a, where ⊕ 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.

Input

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≤t≤1000

) — the number of these values.

The following t

lines contain the values of parameter a, each value is an integer from 0 to 230−1

inclusive.

Output

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.

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

Sample Input

Input
3
0
2
1073741823
Output
1
2
1073741824 题目意思:已知a,求解方程a−(a⊕x)−x=0,x的可能情况有几种。
解题思路:通过移项我们可以得到a⊕x=a-x,那么我们需要找一下这两个表达式的联系和区别。因为是异或,我们将这两个数放在二进制下比较。

1^1=0 1-1=0
   1^0=1 1-0=1
   0^0=0 0-0=0
   0^1=1 0-1=1//借位

我们可以发现,当a=1时,不管对于位上的x是0还是1,都是成立的,但当a=0时,只有x=0成立。
因而发现a=1时可以有两种选择,那么只需要统计a的二进制中1的个数,根据乘法原则就能求出所有解的个数了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
/*
1^1=0 1-1=0
1^0=1 1-0=1
0^0=0 0-0=0
0^1=1 0-1=1//借位
*/
int main()
{
int a,b,t,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d",&a);
ans=;
while(a)
{
if(a%)
{
ans=ans*;
}
a/=;
}
printf("%d\n",ans);
}
return ;
}


CF 1064B Equations of Mathematical Magic(思维规律)的更多相关文章

  1. cf#516B. Equations of Mathematical Magic(二进制,位运算)

    https://blog.csdn.net/zfq17796515982/article/details/83051495 题意:解方程:a-(a^x)-x=0 给出a的值,要求计算解(非负)的个数 ...

  2. B. Equations of Mathematical Magic

    思路 打表找规律,发现结果是,2的(a二进制位为1总数)次方 代码 #include<bits/stdc++.h> using namespace std; #define ll long ...

  3. CF1064B 【Equations of Mathematical Magic】

    题目要求解$a-(a\oplus x)-x=0$的解$x$的个数 移项得$a-x=a\oplus x$ $a$的二进制形式,应该是一个$01$串,异或的过程是不能影响到两个不同的位的,所以我们按位考虑 ...

  4. [ CodeForces 1064 B ] Equations of Mathematical Magic

    \(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...

  5. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  6. Codeforces CF#628 Education 8 D. Magic Numbers

    D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  8. [ 9.29 ]CF每日一题系列—— 765B字符串规律

    Description: 遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果 Solution: 哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了 Code: #include ...

  9. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

随机推荐

  1. Linux搜索查找命令

    Linux搜索查找指令 find,用于在文件树中查找文件并作相应的处理 -name:按照文件名查找文件 -perm:按照文件权限查找文件 -user:按照文件属主来查找文件 -size:按照指定的文件 ...

  2. c模拟内存分配算法(首次适应算法,最佳适应算法,最坏适应算法)

    #include<bits/stdc++.h> using namespace std; /*定义内存的大小为100*/ #define MEMSIZE 100 /*如果小于此值,将不再分 ...

  3. 求助:将以下ES5格式代码转换为ES6格式!!!

    function Slider(id){     //属性     //  1. 通过id获取元素对象(大盒子)     this.bigBox = document.getElementById(i ...

  4. Linux开机自启动脚本

    将需要开机自启动的脚本命令写在文件/etc/rc.d/rc.local中即可. 比如需要开机自启动MySql和Apache,则在/etc/rc.d/rc.local文件尾部加入两行命令: system ...

  5. Linux操作系统基本操作(1)

    1.常用快捷键 Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂停当前程序,暂停后按下任意键恢复运行 Ctrl+z 将当前程序放到后台运行,恢复到前台为命令fg Ctrl+a 将光标移至输入行头 ...

  6. linux查看磁盘占用情况

    一:首先是先登录 二:查看当前目录 命令:df -h 三:查看具体文件夹占用情况 命令:du --max-depth=1 -h  /data/ 或者:为了快算显示,同时也只是想查看目录整体占用大小 命 ...

  7. PHP操作xml学习笔记之增删改查(2)—删、改、查

    xml文件 <?xml version="1.0" encoding="utf-8"?><班级>    <学生>       ...

  8. Hbase的安装和基本使用

    Hbase介绍 HBase是一个开源的非关系型分布式数据库(NoSQL),它参考了谷歌的BigTable建模,实现的编程语言为 Java.它是Apache软件基金会的Hadoop项目的一部分,运行于H ...

  9. 20145209刘一阳《JAVA程序设计》第九周课堂测试

    第九周课堂测试 1.域名解析服务器(ARP)负责将域名转化为IP地址,从而与主机连接.(B) A .true B .false 2.下列关于URL类的说法,正确的是(BD) A .URL 类自身可根据 ...

  10. 二维码Data Matrix编码、解码使用举例

    二维码Data Matrix的介绍见: http://blog.csdn.net/fengbingchun/article/details/44279967  ,这里简单写了个生成二维码和对二维码进行 ...