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 ;
}


最新文章

  1. Ubuntu 安装tftp服务器
  2. js 操作map对象
  3. cc.game
  4. C/C++中堆与栈
  5. c 深度剖析 3
  6. Linux-LNMP LAMP LNMPA
  7. Codeforces Round #338 (Div. 2) A. Bulbs 水题
  8. 使用openoffice将word文件转换为pdf格式遇到问题:The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from required
  9. js学习笔记之:键盘应用
  10. read和onload jquery.val
  11. SQLSERVER 列名无效
  12. wind river hypervisor 2.0.2.1
  13. Oracle 每天自动生成AWR报告
  14. Python_检查程序规范
  15. 浅谈pc和移动端的响应式
  16. Mercurial (hg) Hook : PHP Syntax Check , hg 代码检测 钩子
  17. elasticsearch 基本操作
  18. Codeforces.786B.Legacy(线段树优化建图 最短路Dijkstra)
  19. 55. Jump Game (Array; Greedy)
  20. mysql 判断两个字符串是否存在包含关系-------(1,2,3)与(2,3)

热门文章

  1. mac下git安装和使用
  2. PHP+MySQL实现海量数据导入导出的总结:is_numbric函数的坑
  3. TIDB数据集群部署
  4. WPF字体模糊解决方案
  5. 洛谷 P1580 yyy loves Easter_Egg I
  6. 【SHOI2016】黑暗前的幻想乡
  7. Object C学习笔记1-基本数据类型说明
  8. 异步任务(Celery)详解
  9. 关于AutoMapper和WCF的一些认识
  10. 第一次玩github,第一个开源小项目——xxoo