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. BI之报表测试总结

    报表测试总结: 1.测试准备工作: 数据准备 保证足够多的有效数据 清楚报表中涉及到的算法.公式 清楚业务功能接口 2.报表测试点 基本测试点:界面.控件.格式.布局.明显的数据错误.js报错.报表标 ...

  2. pc端js常用方法

    var common = {}; /** * [pageMask ajax统一请求] * @return {[type]} [description] */ common.pageMask = fun ...

  3. 在Linux中连接android设备

    1.用usb线连接电脑和android设备,在命令行中输入lsusb可查看采用usb连接到电脑的设备 找到设备的vendor ID. 如上图: "Bus 002 Device 007: ID ...

  4. 一、Delphi中Cxgrid表格滚动条粗细设置

    1.Delphi VCL新版本的Cxgrid滚动条默认是触屏模式(如下图),很细的滚动条,在电脑版显示非常不方便. 2.如果需要改成传统的滚动条模式,需要设置一下LookAndFeel里面的Scrol ...

  5. 【转】如何内网搭建NuGet服务器

    原文:http://www.cnblogs.com/zhangweizhong/p/7755332.html NuGet 是.NET程序员熟知的工具,它可以直接安装开源社区中的各个公用组件,可以说是非 ...

  6. PostgreSQL内存使用增长观察

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页 [作者 高健@博客园  luckyjackga ...

  7. 【TJOI2015】线性代数

    题面 题解 要求的是 \[ \sum_{i=1}^n\sum_{j=1}^na_ia_jb_{i,j} - \sum_{i=1}^na_ic_i \] 可以看出这是一个最大权闭合子图问题 代码 #in ...

  8. 【BZOJ1047】[HAOI2007]理想的正方形

    [BZOJ1047][HAOI2007]理想的正方形 题面 bzoj 洛谷 题解 二维\(st\)表,代码是以前的 #include<iostream> #include<cstdi ...

  9. Codeforces 909 D. Colorful Points (模拟)

    题目链接: Colorful Points 题意: 给出一段字符串(长度最大为1e6),每次操作可以删除字符串中所有相邻字符与其不同的字符.例如:aabcaa 删除一次就变成了aa,就无法再删除了.题 ...

  10. 菜鸟vimer成长记——第4.1章、通用插件

    简介 关于插件的分类,此系列只会简单的区分为通用插件和编程插件.通用插件的意思是,不基于任何编程语言都可以使用的插件.编程插件,是针对于编程习惯,或者说是针对于某种语言的插件. 计划中,是先把基本常用 ...